Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
docs: add example to inject a token
  • Loading branch information
timdeschryver committed Sep 23, 2019
commit 4b9fbcdfa429cd2fc54514bafb7ea53b3f2cc914
16 changes: 16 additions & 0 deletions src/app/examples/10-inject-token-dependency.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { render } from '@testing-library/angular';

import { DataInjectedComponent, DATA } from './10-inject-token-dependency';

test('injects data into the component', async () => {
const component = await render(DataInjectedComponent, {
providers: [
{
provide: DATA,
useValue: { text: 'Hello boys and girls'}
}
]
});

expect(component.getByText(/Hello boys and girls/i)).toBeInTheDocument();
});
11 changes: 11 additions & 0 deletions src/app/examples/10-inject-token-dependency.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Component, InjectionToken, Inject } from '@angular/core';

export const DATA = new InjectionToken<{text: string}>('Components Data');

@Component({
selector: 'app-fixture',
template: `{{ data.text }}`,
})
export class DataInjectedComponent {
constructor(@Inject(DATA) public data: {text: string}){}
}