@@ -4,7 +4,7 @@ var base = require('../');
44var expect = require ( 'chai' ) . expect ;
55
66describe ( 'find.js' , function ( ) {
7- it ( 'should return the expected output' , function ( done ) {
7+ it ( 'should return the expected output' , function ( ) {
88 var jsonfile = {
99 path : 'a path' ,
1010 nested : {
@@ -24,11 +24,9 @@ describe('find.js', function () {
2424 expect ( foundKeys [ 0 ] . data ) . to . be . an ( 'string' ) ;
2525 expect ( foundKeys [ 2 ] . data ) . to . be . an ( 'array' ) ;
2626 expect ( foundKeys [ 0 ] . data ) . to . equal ( 'find this string' ) ;
27-
28- done ( ) ;
2927 } ) ;
3028
31- it ( 'should check if it is an array or object' , function ( done ) {
29+ it ( 'should check if it is an array or object' , function ( ) {
3230 var jsonfile = {
3331 findme : [ 'test' ] ,
3432 test : {
@@ -43,7 +41,55 @@ describe('find.js', function () {
4341 expect ( foundKeys [ 0 ] . type ) . to . equal ( 'array' ) ;
4442 expect ( foundKeys [ 1 ] . data ) . to . be . an ( 'object' ) ;
4543 expect ( foundKeys [ 1 ] . type ) . to . equal ( 'object' ) ;
44+ } ) ;
45+
46+ describe ( 'check its options' , function ( ) {
47+ var jsonfile ;
48+
49+ beforeEach ( function ( ) {
50+ jsonfile = {
51+ path : 'a path' ,
52+ nested : {
53+ path : 'a second path' ,
54+ findme : 'find this string' ,
55+ nested : {
56+ path : 'a third path' ,
57+ findme : { test : 'find this an object' }
58+ } ,
59+ } ,
60+ findme : [ 'this is an array' ]
61+ } ;
62+ } ) ;
63+
64+ it ( 'type: should check the type option as string' , function ( ) {
65+ var foundKeys = base . find ( jsonfile , {
66+ type : 'string'
67+ } , 'findme' ) ;
68+
69+ expect ( foundKeys . length ) . to . equal ( 1 ) ;
70+ expect ( foundKeys [ 0 ] . type ) . to . equal ( 'string' ) ;
71+ } ) ;
72+
73+ it ( 'type: should check the type option as array' , function ( ) {
74+ var foundKeys = base . find ( jsonfile , {
75+ type : [ 'object' , 'array' ]
76+ } , 'findme' ) ;
77+
78+ expect ( foundKeys . length ) . to . equal ( 2 ) ;
79+ expect ( foundKeys [ 0 ] . type ) . to . equal ( 'object' ) ;
80+ expect ( foundKeys [ 1 ] . type ) . to . equal ( 'array' ) ;
81+ } ) ;
82+
83+ it ( 'max: should check if the maximum is reduced' , function ( ) {
84+ var foundKeys = base . find ( jsonfile , {
85+ max : 1
86+ } , 'findme' ) ;
87+ var foundKeys2 = base . find ( jsonfile , {
88+ max : 2
89+ } , 'findme' ) ;
4690
47- done ( ) ;
91+ expect ( foundKeys . length ) . to . equal ( 1 ) ;
92+ expect ( foundKeys2 . length ) . to . equal ( 2 ) ;
93+ } ) ;
4894 } ) ;
49- } ) ;
95+ } ) ;
0 commit comments