Skip to content

docs: reproduce #397 #401

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
Aug 14, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { Component, Directive, Input, OnInit } from '@angular/core';
import { render, screen } from '../../src/public_api';

test('the value set in the directive constructor is overriden by the input binding', async () => {
await render(`<atl-fixture [input]="'set by test'" />`, {
imports: [FixtureComponent, InputOverrideViaConstructorDirective],
});

expect(screen.getByText('set by test')).toBeInTheDocument();
});

test('the value set in the directive onInit is used instead of the input binding', async () => {
await render(`<atl-fixture [input]="'set by test'" />`, {
imports: [FixtureComponent, InputOverrideViaOnInitDirective],
});

expect(screen.getByText('set by directive ngOnInit')).toBeInTheDocument();
});

test('the value set in the directive constructor is used instead of the input value', async () => {
await render(`<atl-fixture input='set by test' />`, {
imports: [FixtureComponent, InputOverrideViaConstructorDirective],
});

expect(screen.getByText('set by directive constructor')).toBeInTheDocument();
});

test('the value set in the directive ngOnInit is used instead of the input value and the directive constructor', async () => {
await render(`<atl-fixture input='set by test' />`, {
imports: [FixtureComponent, InputOverrideViaConstructorDirective, InputOverrideViaOnInitDirective],
});

expect(screen.getByText('set by directive ngOnInit')).toBeInTheDocument();
});

@Component({
standalone: true,
selector: 'atl-fixture',
template: `{{ input }}`,
})
class FixtureComponent {
@Input() public input = 'default value';
}

@Directive({
// eslint-disable-next-line @angular-eslint/directive-selector
selector: 'atl-fixture',
standalone: true,
})
class InputOverrideViaConstructorDirective {
constructor(private fixture: FixtureComponent) {
this.fixture.input = 'set by directive constructor';
}
}

@Directive({
// eslint-disable-next-line @angular-eslint/directive-selector
selector: 'atl-fixture',
standalone: true,
})
class InputOverrideViaOnInitDirective implements OnInit {
constructor(private fixture: FixtureComponent) {}

ngOnInit(): void {
this.fixture.input = 'set by directive ngOnInit';
}
}