Skip to content

docs: add directive example #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions apps/example-app/src/app/examples/08-directive.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
import { Component } from '@angular/core';
import { render, screen } from '@testing-library/angular';
import userEvent from '@testing-library/user-event';

import { SpoilerDirective } from './08-directive';

test('it is possible to test directives with container component', async () => {
@Component({
template: `<div appSpoiler data-testid="dir"></div>`,
imports: [SpoilerDirective],
standalone: true,
})
class FixtureComponent {}

const user = userEvent.setup();
await render(FixtureComponent);

const directive = screen.getByTestId('dir');

expect(screen.queryByText('I am visible now...')).not.toBeInTheDocument();
expect(screen.getByText('SPOILER')).toBeInTheDocument();

await user.hover(directive);
expect(screen.queryByText('SPOILER')).not.toBeInTheDocument();
expect(screen.getByText('I am visible now...')).toBeInTheDocument();

await user.unhover(directive);
expect(screen.getByText('SPOILER')).toBeInTheDocument();
expect(screen.queryByText('I am visible now...')).not.toBeInTheDocument();
});

test('it is possible to test directives', async () => {
const user = userEvent.setup();

Expand Down