@@ -120,7 +120,7 @@ describe('Scraper', function () {
120120 } ) ;
121121 } ) ;
122122
123- it ( 'should call loadResource for each url' , function ( done ) {
123+ it ( 'should call loadResource for each url' , function ( ) {
124124 nock ( 'http://first-url.com' ) . get ( '/' ) . reply ( 200 , 'OK' ) ;
125125 nock ( 'http://second-url.com' ) . get ( '/' ) . reply ( 200 , 'OK' ) ;
126126
@@ -133,13 +133,35 @@ describe('Scraper', function () {
133133 } ) ;
134134
135135 var loadResourceSpy = sinon . spy ( s , 'loadResource' ) ;
136- s . load ( ) . then ( function ( ) {
136+ return s . load ( ) . then ( function ( ) {
137137 loadResourceSpy . calledTwice . should . be . eql ( true ) ;
138- done ( ) ;
139- } ) . catch ( done ) ;
138+ } ) ;
139+ } ) ;
140+
141+ it ( 'should not call loadResource if no resource was returned' , function ( ) {
142+ nock ( 'http://first-url.com' ) . get ( '/' ) . reply ( 200 , 'OK' ) ;
143+ nock ( 'http://second-url.com' ) . get ( '/' ) . reply ( 200 , 'OK' ) ;
144+
145+ var s = new Scraper ( {
146+ urls : [
147+ 'http://first-url.com' ,
148+ 'http://second-url.com'
149+ ] ,
150+ directory : testDirname
151+ } ) ;
152+
153+ var loadResourceSpy = sinon . spy ( s , 'loadResource' ) ;
154+ var requestStub = sinon . stub ( s , 'requestResource' ) ;
155+ requestStub . onCall ( 0 ) . resolves ( null ) ;
156+ requestStub . onCall ( 1 ) . resolves ( new Resource ( 'http://second-url.com' ) ) ;
157+
158+ return s . load ( ) . then ( function ( ) {
159+ loadResourceSpy . calledOnce . should . be . eql ( true ) ;
160+ loadResourceSpy . args [ 0 ] [ 0 ] . url . should . be . eql ( 'http://second-url.com' ) ;
161+ } ) ;
140162 } ) ;
141163
142- it ( 'should return array of objects with url, filename and children' , function ( done ) {
164+ it ( 'should return array of objects with url, filename and children' , function ( ) {
143165 nock ( 'http://first-url.com' ) . get ( '/' ) . reply ( 200 , 'OK' ) ;
144166 nock ( 'http://second-url.com' ) . get ( '/' ) . reply ( 500 ) ;
145167
@@ -151,13 +173,12 @@ describe('Scraper', function () {
151173 directory : testDirname
152174 } ) ;
153175
154- s . load ( ) . then ( function ( res ) {
176+ return s . load ( ) . then ( function ( res ) {
155177 res . should . be . instanceOf ( Array ) ;
156178 res . should . have . length ( 2 ) ;
157179 res [ 0 ] . should . be . instanceOf ( Resource ) . and . have . properties ( [ 'url' , 'filename' , 'children' ] ) ;
158180 res [ 1 ] . should . be . instanceOf ( Resource ) . and . have . properties ( [ 'url' , 'filename' , 'children' ] ) ;
159- done ( ) ;
160- } ) . catch ( done ) ;
181+ } ) ;
161182 } ) ;
162183 } ) ;
163184
0 commit comments