How to test jQuery error callback?

This is the jquery function:

$.get("/url", function(){ //success }).fail(function(){ //fail <---- how to make code go in there. }); 

The problem is how to run the program in the .fail block, I am using .Net MVC. However, setting a breakpoint in the controller does not throw a timeout exception, but causes a failure.

I don’t know how people test this.

Should I start browsing some tools?

+8
javascript jquery
source share
2 answers

Put this in your controller method:

 return new HttpStatusCodeResult(HttpStatusCode.NotFound); 
+1
source share

Use invalid final URL. You should get 404 - not found http status code error.

0
source share

All Articles