Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8ce5b10

Browse files
docs: add example to inject a token (testing-library#53)
1 parent ced7046 commit 8ce5b10

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { render } from '@testing-library/angular';
2+
3+
import { DataInjectedComponent, DATA } from './10-inject-token-dependency';
4+
5+
test('injects data into the component', async () => {
6+
const component = await render(DataInjectedComponent, {
7+
providers: [
8+
{
9+
provide: DATA,
10+
useValue: { text: 'Hello boys and girls' },
11+
},
12+
],
13+
});
14+
15+
expect(component.getByText(/Helloboysandgirls/i)).toBeInTheDocument();
16+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Component, InjectionToken, Inject } from '@angular/core';
2+
3+
export const DATA = new InjectionToken<{ text: string }>('Components Data');
4+
5+
@Component({
6+
selector: 'app-fixture',
7+
template: `
8+
{{ data.text }}
9+
`,
10+
})
11+
export class DataInjectedComponent {
12+
constructor(@Inject(DATA) public data: { text: string }) {}
13+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /