-
Notifications
You must be signed in to change notification settings - Fork 1
/
watch.spec.ts
72 lines (61 loc) · 2 KB
/
watch.spec.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import SampleComponent from '@spec/SampleComponent.vue';
import BlankComponent from '@spec/BlankComponent.vue';
import PlaneObjectComponent from '@spec/PlaneObjectComponent.vue';
import InvalidComponent from '@spec/InvalidComponent.vue';
import { watch } from '@src/index';
describe('Watch', () => {
describe('extraction', () => {
it('extracts hooks', () => {
const { count } = watch(SampleComponent);
expect(typeof count).toBe('function');
expect(typeof count()).toBe('object');
});
});
describe('mock', () => {
const { count } = watch(SampleComponent);
describe('mock methods', () => {
it('calls other method', () => {
expect(count(1).run().otherMethod).toBeCalled();
});
});
describe('context', () => {
it('chaneges context value', () => {
const result = count(15).run({ output: '' });
expect(result.output).toBe('Fizz Buzz');
});
});
});
describe('no watcher', () => {
it('throws no watcher error', () => {
expect(() => {
watch(BlankComponent);
}).toThrow('Not exists watcher.');
});
});
describe('invalid component', () => {
it('throws no invalid component error', () => {
expect(() => {
watch(InvalidComponent);
}).toThrow('Illegal component. component must be object or function.');
});
});
describe('plane object', () => {
it('returns mock function', () => {
const { count } = watch(PlaneObjectComponent);
expect(typeof count).toBe('function');
expect(count().run().return).toBe(undefined);
});
});
describe('alias', () => {
const { count } = watch(SampleComponent);
it('returns value by alias "r"', () => {
expect(count(1).r().return).toBe(undefined);
});
it('returns value by function property alias "run"', () => {
expect(count.run().return).toBe(undefined);
});
it('returns value by function property alias "r"', () => {
expect(count.r().return).toBe(undefined);
});
});
});