1
1
'use strict' ;
2
2
/* globals: describe, it */
3
3
4
- var expect = require ( 'chai' ) . expect ;
4
+ var chai = require ( 'chai' ) ;
5
+ var expect = chai . expect ;
6
+ var sinon = require ( 'sinon' ) ;
5
7
var getFiles = require ( '../../lib/get-files' ) ;
6
8
var fixturesDir = process . cwd ( ) + '/test/fixtures' ;
7
9
10
+ chai . use ( require ( 'sinon-chai' ) ) ;
11
+
8
12
/** @name describe @function */
9
13
/** @name it @function */
10
14
/** @name before @function */
@@ -23,12 +27,24 @@ describe('Get files', function() {
23
27
} ) ;
24
28
} ) ;
25
29
26
- describe ( '#asJSON ' , function ( ) {
30
+ describe ( '#asObjects ' , function ( ) {
27
31
it ( 'should return a mapped object of JSON contents, keyed by file name' , function ( ) {
28
- return getFiles . asJSON ( [ fixturesDir + '/schema1.json' , fixturesDir + '/schema2.json' ] ) . then ( function ( map ) {
32
+ return getFiles . asObjects ( [ fixturesDir + '/schema1.json' , fixturesDir + '/schema2.json' ] ) . then ( function ( map ) {
33
+ expect ( map ) . to . be . an ( 'object' ) ;
34
+ expect ( map ) . to . have . property ( fixturesDir + '/schema1.json' ) . that . is . an ( 'object' ) ;
35
+ expect ( map ) . to . have . property ( fixturesDir + '/schema2.json' ) . that . is . an ( 'object' ) ;
36
+ } ) ;
37
+ } ) ;
38
+
39
+ it ( 'should allow to specify a custom parser, keyed by file name' , function ( ) {
40
+ var cb = sinon . spy ( JSON . parse ) ;
41
+ return getFiles . asObjects ( [ fixturesDir + '/schema1.json' , fixturesDir + '/schema2.json' ] , cb ) . then ( function ( map ) {
29
42
expect ( map ) . to . be . an ( 'object' ) ;
30
43
expect ( map ) . to . have . property ( fixturesDir + '/schema1.json' ) . that . is . an ( 'object' ) ;
31
44
expect ( map ) . to . have . property ( fixturesDir + '/schema2.json' ) . that . is . an ( 'object' ) ;
45
+ expect ( cb ) . to . have . been . calledTwice ;
46
+ expect ( cb ) . to . have . been . calledWithMatch ( sinon . match . string , fixturesDir + '/schema1.json' ) ;
47
+ expect ( cb ) . to . have . been . calledWithMatch ( sinon . match . string , fixturesDir + '/schema2.json' ) ;
32
48
} ) ;
33
49
} ) ;
34
50
} ) ;
0 commit comments