Skip to content

Commit

Permalink
docs: use on in docs (#469)
Browse files Browse the repository at this point in the history
Closes #468
  • Loading branch information
timdeschryver authored Jul 23, 2024
1 parent 679c5f9 commit 40fe4ea
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
58 changes: 57 additions & 1 deletion apps/example-app/src/app/examples/02-input-output.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,62 @@ test('is possible to set input and listen for output', async () => {
const user = userEvent.setup();
const sendValue = jest.fn();

await render(InputOutputComponent, {
componentInputs: {
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('<app-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, {
componentInputs: {
value: 47,
Expand Down Expand Up @@ -34,7 +90,7 @@ test('is possible to set input and listen for output', async () => {
expect(sendValue).toHaveBeenCalledWith(50);
});

test('is possible to set input and listen for output with the template syntax', async () => {
test('is possible to set input and listen for output with the template syntax (deprecated)', async () => {
const user = userEvent.setup();
const sendSpy = jest.fn();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ test('output emits a value', async () => {
greeting: 'Hello',
name: 'world',
},
componentOutputs: {
submit: { emit: submitFn } as any,
on: {
submit: submitFn,
},
});

Expand Down

0 comments on commit 40fe4ea

Please sign in to comment.