diff --git a/Gruntfile.js b/Gruntfile.js index 32a77a6..d14453e 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -94,7 +94,8 @@ module.exports = exports = function(grunt) { 'http://localhost:9999/test/test.nodriver.html', 'http://localhost:9999/test/test.main.html', 'http://localhost:9999/test/test.min.html', - 'http://localhost:9999/test/test.require.html' + 'http://localhost:9999/test/test.require.html', + 'http://localhost:9999/test/test.callwhenready.html' ] } } diff --git a/test/test.api.js b/test/test.api.js index b8e7fcb..bf5c74f 100644 --- a/test/test.api.js +++ b/test/test.api.js @@ -1,4 +1,4 @@ -/* global after:true, before:true, beforeEach:true, describe:true, expect:true, it:true, Modernizr:true, Promise:true, require:true */ +/* global afterEach:true, before:true, beforeEach:true, describe:true, expect:true, it:true, Modernizr:true, Promise:true, require:true */ var DRIVERS = [ localforage.INDEXEDDB, localforage.LOCALSTORAGE, @@ -424,7 +424,7 @@ DRIVERS.forEach(function(driverName) { var _oldReady; - before(function(done) { + beforeEach(function(done) { _oldReady = localforage.ready; localforage.ready = function() { return Promise.reject(); @@ -432,7 +432,7 @@ DRIVERS.forEach(function(driverName) { done(); }); - after(function(done) { + afterEach(function(done) { localforage.ready = _oldReady; _oldReady = null; done(); diff --git a/test/test.callwhenready.html b/test/test.callwhenready.html new file mode 100644 index 0000000..dcf1ca7 --- /dev/null +++ b/test/test.callwhenready.html @@ -0,0 +1,42 @@ + + + + + localForage callWhenReady Tests! + + + + + + + + + + + + + + + + + + + + + + +
+ + diff --git a/test/test.callwhenready.js b/test/test.callwhenready.js new file mode 100644 index 0000000..97e0375 --- /dev/null +++ b/test/test.callwhenready.js @@ -0,0 +1,19 @@ +/* global beforeEach:true */ +var mocha = this.mocha; + +mocha.setup('bdd'); + +beforeEach(function(done) { + var previousDriver = localforage.driver(); + + // Undefine localforage module to force reload, which will cause the + // API calls in tests to be called before the drivers are asynchronously + // loaded again, thus testing the API method stubs which delay the actual + // driver API calls till ready(). + require.undef('/dist/localforage.js'); + require(['/dist/localforage.js'], function(localforage) { + localforage.setDriver(previousDriver); + window.localforage = localforage; + done(); + }); +});