1 |
|
2 | describe('When Driver Fails to Initialize', function() {
|
3 | 'use strict';
|
4 |
|
5 | var FAULTYDRIVERS = [
|
6 | localforage.INDEXEDDB,
|
7 | localforage.WEBSQL,
|
8 | localforage.LOCALSTORAGE
|
9 | ]
|
10 | .filter(localforage.supports)
|
11 | .filter(function(driverName) {
|
12 |
|
13 |
|
14 |
|
15 | return !(
|
16 | driverName === localforage.LOCALSTORAGE &&
|
17 | localStorage.setItem.toString().indexOf('[native code]') >= 0
|
18 | );
|
19 | });
|
20 |
|
21 | FAULTYDRIVERS.forEach(function(driverName) {
|
22 | describe(driverName, function() {
|
23 |
|
24 | beforeEach(function() {
|
25 | if (driverName === localforage.LOCALSTORAGE) {
|
26 | localStorage.clear();
|
27 | }
|
28 | });
|
29 |
|
30 | it('fails to setDriver ' + driverName + ' [callback]', function(done) {
|
31 | localforage.setDriver(driverName, function() {
|
32 | localforage.ready(function(err) {
|
33 | expect(err).to.be.an(Error);
|
34 | expect(err.message).to.be('No available storage method found.');
|
35 | done();
|
36 | });
|
37 | });
|
38 | });
|
39 |
|
40 | it('fails to setDriver ' + driverName + ' [promise]', function(done) {
|
41 | localforage.setDriver(driverName).then(function() {
|
42 | return localforage.ready();
|
43 | }).then(null, function(err) {
|
44 | expect(err).to.be.an(Error);
|
45 | expect(err.message).to.be('No available storage method found.');
|
46 | done();
|
47 | });
|
48 | });
|
49 | });
|
50 | });
|
51 |
|
52 | });
|