UNPKG

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