mirror of
https://github.com/localForage/localForage.git
synced 2026-02-01 15:32:04 +00:00
Apply "root" level beforeEach hook to run test suite against callWhenReady API method stubs
This commit is contained in:
parent
1565d51a41
commit
85e980aefb
@ -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'
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
42
test/test.callwhenready.html
Normal file
42
test/test.callwhenready.html
Normal file
@ -0,0 +1,42 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>localForage callWhenReady Tests!</title>
|
||||
|
||||
<link rel="stylesheet" type="text/css"
|
||||
href="/bower_components/mocha/mocha.css">
|
||||
|
||||
<script src="/bower_components/assert/assert.js"></script>
|
||||
<script src="/bower_components/mocha/mocha.js"></script>
|
||||
|
||||
<script src="/bower_components/expect/index.js"></script>
|
||||
|
||||
<!-- require.js -->
|
||||
<script src="/bower_components/requirejs/require.js"></script>
|
||||
|
||||
<!-- Modernizr -->
|
||||
<script src="/bower_components/modernizr/modernizr.js"></script>
|
||||
|
||||
<!-- Apply "root" level beforeEach hook to run test suite against
|
||||
callWhenReady API method stubs -->
|
||||
<script src="/test/test.callwhenready.js"></script>
|
||||
|
||||
<!-- Test runner -->
|
||||
<script>
|
||||
// Skip irrelevant config tests by mapping them to API tests so that
|
||||
// they will not be called.
|
||||
requirejs.config({
|
||||
map: {
|
||||
'*': {
|
||||
'/test/test.config.js': '/test/test.api.js'
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script src="/test/runner.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
</body>
|
||||
</html>
|
||||
19
test/test.callwhenready.js
Normal file
19
test/test.callwhenready.js
Normal file
@ -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();
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user