forked from localForage/localForage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.faultydriver.js
61 lines (57 loc) · 2.08 KB
/
test.faultydriver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* global beforeEach:true, describe:true, expect:true, it:true */
describe('When Driver Fails to Initialize', function() {
'use strict';
var FAULTYDRIVERS = [
localforage.INDEXEDDB,
localforage.WEBSQL,
localforage.LOCALSTORAGE
]
.filter(localforage.supports)
.filter(function(driverName) {
// FF doesn't allow you to override `localStorage.setItem`
// so if the faulty driver setup didn't succeed
// then skip the localStorage tests
return !(
driverName === localforage.LOCALSTORAGE &&
localStorage.setItem.toString().indexOf('[native code]') >= 0
);
});
FAULTYDRIVERS.forEach(function(driverName) {
describe(driverName, function() {
beforeEach(function() {
if (driverName === localforage.LOCALSTORAGE) {
localStorage.clear();
}
});
it('fails to setDriver ' + driverName + ' [callback]', function(
done
) {
localforage.setDriver(driverName, function() {
localforage.ready(function(err) {
expect(err).to.be.an(Error);
expect(err.message).to.be(
'No available storage method found.'
);
done();
});
});
});
it('fails to setDriver ' + driverName + ' [promise]', function(
done
) {
localforage
.setDriver(driverName)
.then(function() {
return localforage.ready();
})
.then(null, function(err) {
expect(err).to.be.an(Error);
expect(err.message).to.be(
'No available storage method found.'
);
done();
});
});
});
});
});