-
Notifications
You must be signed in to change notification settings - Fork 32
/
callback.test.js
38 lines (27 loc) · 1.02 KB
/
callback.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
describe('DAY 9: Callback', () => {
it(`(Synchronous callback)
create a function named caller
deduce the rest of the implementation reading the 2 expects`, () => {
let callback = jest.fn();
let callbackArgument = Symbol('callbackArgument');
/**
*
* @param {function} callback
* @returns {undefined}
*/
let caller = () => {};
let result = caller(callback);
expect(callback).toBeCalledWith(callbackArgument);
expect(result).toBe(callback);
});
it(`(Asynchronous callback)
change the function "caller"
deduce the implementation reading the 2 expects`, done => {
let callback = jest.fn();
let callbackArgument = Symbol('callbackArgument');
// @see https://jestjs.io/docs/en/asynchronous
let caller = () => {};
setTimeout(() => expect(callback).toBeCalledWith(callbackArgument), 1000);
setTimeout(() => caller(callback), 50);
}, 2000);
});