11'use strict' ;
22/* globals: describe, it */
33
4- var expect = require ( 'chai' ) . expect ;
4+ var chai = require ( 'chai' ) ;
5+ var expect = chai . expect ;
6+ var sinon = require ( 'sinon' ) ;
57var getFiles = require ( '../../lib/get-files' ) ;
68var fixturesDir = process . cwd ( ) + '/test/fixtures' ;
79
10+ chai . use ( require ( 'sinon-chai' ) ) ;
11+
812/** @name describe @function */
913/** @name it @function */
1014/** @name before @function */
@@ -23,12 +27,24 @@ describe('Get files', function() {
2327 } ) ;
2428 } ) ;
2529
26- describe ( '#asJSON ' , function ( ) {
30+ describe ( '#asObjects ' , function ( ) {
2731 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 ) {
2942 expect ( map ) . to . be . an ( 'object' ) ;
3043 expect ( map ) . to . have . property ( fixturesDir + '/schema1.json' ) . that . is . an ( 'object' ) ;
3144 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' ) ;
3248 } ) ;
3349 } ) ;
3450 } ) ;
0 commit comments