@@ -34,8 +34,8 @@ test('waits 1 second before ending the game', () => {
3434 const timerGame = require (' ../timerGame' );
3535 timerGame ();
3636
37- expect (setTimeout . mock . calls . length ). toBe (1 );
38- expect (setTimeout . mock . calls [ 0 ][ 1 ]). toBe ( 1000 );
37+ expect (setTimeout). toHaveBeenCalledTimes (1 )
38+ expect (setTimeout). toHaveBeenLastCalledWith ( expect . any ( Function ), 1000 );
3939});
4040```
4141
@@ -63,7 +63,7 @@ test('calls the callback after 1 second', () => {
6363
6464 // Now our callback should have been called!
6565 expect (callback).toBeCalled ();
66- expect (callback . mock . calls . length ). toBe (1 );
66+ expect (callback). toHaveBeenCalledTimes (1 )
6767});
6868```
6969
@@ -110,8 +110,8 @@ describe('infiniteTimerGame', () => {
110110
111111 // At this point in time, there should have been a single call to
112112 // setTimeout to schedule the end of the game in 1 second.
113- expect (setTimeout . mock . calls . length ). toBe (1 );
114- expect (setTimeout . mock . calls [ 0 ][ 1 ]). toBe ( 1000 );
113+ expect (setTimeout). toHaveBeenCalledTimes (1 )
114+ expect (setTimeout). toHaveBeenLastCalledWith ( expect . any ( Function ), 1000 );
115115
116116 // Fast forward and exhaust only currently pending timers
117117 // (but not any new timers that get created during that process)
@@ -122,8 +122,8 @@ describe('infiniteTimerGame', () => {
122122
123123 // And it should have created a new timer to start the game over in
124124 // 10 seconds
125- expect (setTimeout . mock . calls . length ). toBe (2 );
126- expect (setTimeout . mock . calls [ 1 ][ 1 ]). toBe ( 10000 );
125+ expect (setTimeout). toHaveBeenCalledTimes (2 )
126+ expect (setTimeout). toHaveBeenLastCalledWith ( expect . any ( Function ), 10000 );
127127 });
128128});
129129```
@@ -170,7 +170,7 @@ it('calls the callback after 1 second via advanceTimersByTime', () => {
170170
171171 // Now our callback should have been called!
172172 expect (callback).toBeCalled ();
173- expect (callback . mock . calls . length ). toBe (1 );
173+ expect (callback). toHaveBeenCalledTimes (1 )
174174});
175175```
176176
0 commit comments