-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
functions.test.ts
40 lines (32 loc) · 1.03 KB
/
functions.test.ts
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
import { createMock } from 'ts-auto-mock';
import { method, On } from 'ts-auto-mock/extension';
describe('functions', () => {
let mock: A;
type A = () => void;
beforeEach(() => {
mock = createMock<A>();
});
it('should work as a spy', () => {
function hello(myMethod: A): void {
myMethod();
}
hello(mock);
expect(mock).toHaveBeenCalled();
});
it('should not be able to get the mock', () => {
expect(() => {
On(mock).get(method((x: A) => x.apply));
}).toThrow();
});
it('should create different factories for different functions mock', () => {
interface AMock {
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
first: Function;
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
second: Function;
}
const anotherMock: AMock = createMock<AMock>();
expect((anotherMock.first as jasmine.Spy).and.identity).toBe('first');
expect((anotherMock.second as jasmine.Spy).and.identity).toBe('second');
});
});