forked from brendon1982/ts-mocking-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_object_callback.test.ts
More file actions
46 lines (42 loc) · 1.1 KB
/
01_object_callback.test.ts
File metadata and controls
46 lines (42 loc) · 1.1 KB
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
39
40
41
42
43
44
45
46
import { describe, it } from 'mocha'
import { expect } from 'chai'
import sinon from 'sinon'
import { execute } from '../tests-to-implement/01_object_callback'
describe('object mock callback', () => {
let createPayload = (amount = 10, id = "test") => {
return {
id: id,
amount: amount,
callback: (result: string) => {}
}
}
describe('execute', () => {
it('calls the callback', () => {
// Arrange
let payload = createPayload();
let spy = sinon.spy(payload, 'callback');
// Act
execute(payload);
// Assert
expect(spy).called;
})
it('calls the callback once', () => {
// Arrange
let payload = createPayload();
let spy = sinon.spy(payload, 'callback');
// Act
execute(payload);
// Assert
expect(spy).calledOnce;
})
it('calls the callback with correct value', () => {
// Arrange
let payload = createPayload(10, 'abcd');
let spy = sinon.spy(payload, 'callback');
// Act
execute(payload);
// Assert
expect(spy).calledWith('100 for abcd');
})
})
})