javascript - How to test a disconnection when testing an AJAX application? -


i'm testing ajax application need handle temporary loss of connection server or other errors (i.e. in gmail or google calendar.) what's way simulate in testing?

for example, there browser plugin allow 1 temporarily "turn off" internet connection tab? debugging in chrome particularly helpful if offer suggestion browser.

other options i've tried toggling network connection vm server, or shutting down server , restarting it, neither of lightweight or easy testing (the latter doesn't preserve state.)

clarification: i'm not interested in how test disconnection handling in test code. want create disconnection test when running app. ideally, toggled in 1 tab of browser doesn't involve borking entire internet connection.

on question, knowing framework using test thing. rest, if ajax stuff handled xmlhttprequest object, there little can do, once request has fired, cannot control anymore. if using framework such jquery, consider juking events. involves firing event in synthetic fashion. in order do, if event handlers public in scope (which should if writing maintainable code), should able fire them. if not, make them public.

failing that, can act on server side by:

  1. setting "test mode" server drops connection @ specific time
  2. consider routing through configurable proxy (nginx?) implement step 1 without modifying server
  3. fire disconnection handler synthetically rather event. know event handler xmlhttprequest failing working - that's assured browser not being buggy. need test if function works.

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -