1
1
2
2
import { Cachier } from '../../src/cachier'
3
3
4
- function shouldReject ( promise ) {
5
- return Promise . resolve ( promise )
6
- . then (
7
- ( ) => { throw new Error ( 'should not be success' ) } ,
8
- ( ) => 'ok, error is thrown'
9
- )
10
- }
11
-
12
4
describe ( 'Cachier' , function ( ) {
13
5
14
6
let cachier
@@ -30,20 +22,19 @@ describe('Cachier', function() {
30
22
describe ( '.connection' , ( ) => {
31
23
it ( 'should be a promise which fullfill with the db connection' , ( ) => {
32
24
return cachier . connection . then ( function ( db ) {
33
- expect ( db . constructor + '' ) . toMatch ( / D B D a t a b a s e / )
25
+ expect ( db . constructor + '' ) . to . match ( / D B D a t a b a s e / )
34
26
} )
35
27
} )
36
28
} )
37
29
38
30
describe ( '#save' , ( ) => {
39
31
it ( 'stores a blob' , ( ) => {
40
32
let blob = new Blob ( [ 'hello' ] )
41
- return cachier . save ( 'wow' , blob )
42
- . then ( result => expect ( result ) . toBeTruthy ( ) )
33
+ return expect ( cachier . save ( 'wow' , blob ) ) . to . eventually . be . ok
43
34
} )
44
35
it ( 'rejects when key is invalid' , ( ) => {
45
36
let blob = new Blob ( [ 'hello' ] )
46
- return shouldReject ( cachier . save ( undefined , blob ) )
37
+ return expect ( cachier . save ( undefined , blob ) ) . to . be . rejected
47
38
} )
48
39
} )
49
40
@@ -57,8 +48,8 @@ describe('Cachier', function() {
57
48
describe ( '#load' , function ( ) {
58
49
it ( 'should return the blob value' , ( ) => {
59
50
return cachier . load ( 'wow2' ) . then ( function ( { blob, metadata } ) {
60
- expect ( blob . size ) . toBe ( 5 )
61
- expect ( metadata ) . toEqual ( { name : 'example1' } )
51
+ expect ( blob . size ) . to . equal ( 5 )
52
+ expect ( metadata ) . to . deep . equal ( { name : 'example1' } )
62
53
} )
63
54
} )
64
55
} )
@@ -70,16 +61,16 @@ describe('Cachier', function() {
70
61
. delay ( 10 ) // chrome needs this delay
71
62
. then ( ( ) => cachier . load ( 'wow2' ) )
72
63
. then ( function ( { blob, metadata } ) {
73
- expect ( blob . size ) . toBe ( 6 )
74
- expect ( metadata ) . toBe ( undefined )
64
+ expect ( blob . size ) . to . equal ( 6 )
65
+ expect ( metadata ) . to . equal ( undefined )
75
66
} )
76
67
} )
77
68
} )
78
69
79
70
describe ( '#delete' , function ( ) {
80
71
it ( 'should remove the blob' , ( ) => {
81
- return shouldReject ( cachier . delete ( 'wow3' )
82
- . then ( ( ) => cachier . load ( 'wow3' ) ) )
72
+ return cachier . delete ( 'wow3' )
73
+ . then ( ( ) => expect ( cachier . load ( 'wow3' ) ) . to . be . rejected )
83
74
} )
84
75
} )
85
76
@@ -99,8 +90,8 @@ describe('Cachier', function() {
99
90
. delay ( 10 )
100
91
. then ( ( ) => cachier . load ( 'wow4' ) )
101
92
. then ( function ( { blob } ) {
102
- expect ( blob . size ) . toBe ( 5 )
103
- expect ( blob . type ) . toBe ( 'text/plain' )
93
+ expect ( blob . size ) . to . equal ( 5 )
94
+ expect ( blob . type ) . to . equal ( 'text/plain' )
104
95
} )
105
96
} )
106
97
} )
0 commit comments