UI for Zipcoin Blue

test.callwhenready.js 1.3KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* global beforeEach:true */
  2. this.mocha.setup('bdd');
  3. beforeEach(function(done) {
  4. var previousDriver = localforage.driver();
  5. function rerequirelocalforage() {
  6. // The API method stubs inserted by callWhenReady must be tested before
  7. // they are replaced by the driver, which happens as soon as it loads.
  8. //
  9. // To ensure that they work when the drivers are loaded asynchronously,
  10. // we run the entire test suite (except for config tests), but undefine
  11. // the localforage module and force it to reload before each test, so that
  12. // it will be initialized again.
  13. //
  14. // This ensures that the synchronous parts of localforage initialization
  15. // and the API calls in the tests occur first in every test, such that the
  16. // callWhenReady API method stubs are called before RequireJS
  17. // asynchronously loads the drivers that replace them.
  18. require.undef('localforage');
  19. require(['localforage'], function(localforage) {
  20. localforage.setDriver(previousDriver);
  21. window.localforage = localforage;
  22. done();
  23. });
  24. }
  25. localforage.ready().then(function() {
  26. previousDriver = localforage.driver();
  27. rerequirelocalforage();
  28. }, function() {
  29. rerequirelocalforage();
  30. });
  31. });