-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy path02-input-output.spec.ts
118 lines (93 loc) · 3.51 KB
/
02-input-output.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { render, screen } from '@testing-library/angular';
import userEvent from '@testing-library/user-event';
import { InputOutputComponent } from './02-input-output';
test('is possible to set input and listen for output', async () => {
const user = userEvent.setup();
const sendValue = jest.fn();
await render(InputOutputComponent, {
inputs: {
value: 47,
},
on: {
sendValue,
},
});
const incrementControl = screen.getByRole('button', { name: /increment/i });
const sendControl = screen.getByRole('button', { name: /send/i });
const valueControl = screen.getByTestId('value');
expect(valueControl).toHaveTextContent('47');
await user.click(incrementControl);
await user.click(incrementControl);
await user.click(incrementControl);
expect(valueControl).toHaveTextContent('50');
await user.click(sendControl);
expect(sendValue).toHaveBeenCalledTimes(1);
expect(sendValue).toHaveBeenCalledWith(50);
});
test.skip('is possible to set input and listen for output with the template syntax', async () => {
const user = userEvent.setup();
const sendSpy = jest.fn();
await render('<atl-fixture [value]="47" (sendValue)="sendValue($event)" />', {
imports: [InputOutputComponent],
on: {
sendValue: sendSpy,
},
});
const incrementControl = screen.getByRole('button', { name: /increment/i });
const sendControl = screen.getByRole('button', { name: /send/i });
const valueControl = screen.getByTestId('value');
expect(valueControl).toHaveTextContent('47');
await user.click(incrementControl);
await user.click(incrementControl);
await user.click(incrementControl);
expect(valueControl).toHaveTextContent('50');
await user.click(sendControl);
expect(sendSpy).toHaveBeenCalledTimes(1);
expect(sendSpy).toHaveBeenCalledWith(50);
});
test('is possible to set input and listen for output (deprecated)', async () => {
const user = userEvent.setup();
const sendValue = jest.fn();
await render(InputOutputComponent, {
inputs: {
value: 47,
},
componentOutputs: {
sendValue: {
emit: sendValue,
} as any,
},
});
const incrementControl = screen.getByRole('button', { name: /increment/i });
const sendControl = screen.getByRole('button', { name: /send/i });
const valueControl = screen.getByTestId('value');
expect(valueControl).toHaveTextContent('47');
await user.click(incrementControl);
await user.click(incrementControl);
await user.click(incrementControl);
expect(valueControl).toHaveTextContent('50');
await user.click(sendControl);
expect(sendValue).toHaveBeenCalledTimes(1);
expect(sendValue).toHaveBeenCalledWith(50);
});
test('is possible to set input and listen for output with the template syntax (deprecated)', async () => {
const user = userEvent.setup();
const sendSpy = jest.fn();
await render('<atl-fixture [value]="47" (sendValue)="sendValue($event)" />', {
imports: [InputOutputComponent],
componentProperties: {
sendValue: sendSpy,
},
});
const incrementControl = screen.getByRole('button', { name: /increment/i });
const sendControl = screen.getByRole('button', { name: /send/i });
const valueControl = screen.getByTestId('value');
expect(valueControl).toHaveTextContent('47');
await user.click(incrementControl);
await user.click(incrementControl);
await user.click(incrementControl);
expect(valueControl).toHaveTextContent('50');
await user.click(sendControl);
expect(sendSpy).toHaveBeenCalledTimes(1);
expect(sendSpy).toHaveBeenCalledWith(50);
});