11var imgur = require ( '../lib/imgur.js' ) ,
2- chai = require ( 'chai' ) ,
3- chaiAsPromised = require ( 'chai-as-promised' ) ,
4- expect = chai . expect ,
5- Q = require ( 'q' ) ,
6- sinon = require ( 'sinon' ) ,
7- sinonChai = require ( 'sinon-chai' ) ;
8-
9- chai . use ( sinonChai ) ;
10- chai . use ( chaiAsPromised ) ;
2+ Q = require ( 'q' ) ;
113
124describe ( 'SEARCH' , function ( ) {
135 describe ( 'search options validations' , function ( ) {
14- it ( 'should fail when query is not passed' , function ( done ) {
6+ test ( 'should fail when query is not passed' , function ( ) {
157 var errMsg =
168 'Search requires a query. Try searching with a query (e.g cats).' ;
17- expect ( imgur . search ( ) ) . to . be . rejectedWith ( errMsg ) . and . notify ( done ) ;
9+ expect ( imgur . search ( ) ) . rejects . toMatch ( errMsg ) ;
1810 } ) ;
1911
20- it ( 'should fail when query is passed a boolean' , function ( done ) {
12+ test ( 'should fail when query is passed a boolean' , function ( ) {
2113 var errMsg = 'You did not pass a string as a query.' ;
22- expect ( imgur . search ( true ) ) . to . be . rejectedWith ( errMsg ) . and . notify ( done ) ;
14+ expect ( imgur . search ( true ) ) . rejects . toMatch ( errMsg ) ;
2315 } ) ;
2416
25- it ( 'should fail when query is passed a number' , function ( done ) {
17+ test ( 'should fail when query is passed a number' , function ( ) {
2618 var errMsg = 'You did not pass a string as a query.' ;
27- expect ( imgur . search ( 1 ) ) . to . be . rejectedWith ( errMsg ) . and . notify ( done ) ;
19+ expect ( imgur . search ( 1 ) ) . rejects . toMatch ( errMsg ) ;
2820 } ) ;
2921
30- it ( 'should fail when query is passed a number' , function ( done ) {
22+ test ( 'should fail when query is passed a number' , function ( ) {
3123 var errMsg = 'You did not pass a string as a query.' ;
32- expect ( imgur . search ( 1 ) ) . to . be . rejectedWith ( errMsg ) . and . notify ( done ) ;
24+ expect ( imgur . search ( 1 ) ) . rejects . toMatch ( errMsg ) ;
3325 } ) ;
3426 } ) ;
3527
36- describe ( "delegates to # _imgurRequest('search', ...)" , function ( ) {
28+ describe ( "delegates to _imgurRequest('search', ...)" , function ( ) {
3729 var mockResult = {
3830 data : [ ] ,
3931 params : {
@@ -43,26 +35,30 @@ describe('SEARCH', function () {
4335 } ,
4436 } ;
4537 var payload = '/viral/month/1?q=meme' ;
38+ var _imgurRequestBackup = imgur . _imgurRequest ;
4639
4740 beforeEach ( function ( ) {
4841 var deferred = Q . defer ( ) ;
49- sinon . stub ( imgur , '_imgurRequest' ) . returns ( deferred . promise ) ;
42+ imgur . _imgurRequest = jest
43+ . fn ( )
44+ . mockImplementation ( ( ) => deferred . promise ) ;
5045 deferred . resolve ( mockResult ) ;
5146 } ) ;
5247
5348 afterEach ( function ( ) {
54- imgur . _imgurRequest . restore ( ) ;
49+ imgur . _imgurRequest . mockClear ( ) ;
50+ imgur . _imgurRequest = _imgurRequestBackup ;
5551 } ) ;
5652
57- it ( 'should delegate' , function ( done ) {
53+ it ( 'should delegate' , function ( ) {
5854 var promise = imgur . search ( 'meme' , {
5955 sort : 'viral' ,
6056 dateRange : 'month' ,
6157 page : '1' ,
6258 } ) ;
6359
64- expect ( imgur . _imgurRequest ) . to . have . been . calledWith ( 'search' , payload ) ;
65- expect ( promise ) . to . eventually . deep . equal ( mockResult ) . and . notify ( done ) ;
60+ expect ( imgur . _imgurRequest ) . toHaveBeenCalledWith ( 'search' , payload ) ;
61+ expect ( promise ) . resolves . toMatchObject ( mockResult ) ;
6662 } ) ;
6763 } ) ;
6864} ) ;
0 commit comments