diff --git a/src/app/examples/10-inject-token-dependency.spec.ts b/src/app/examples/10-inject-token-dependency.spec.ts new file mode 100644 index 00000000..27d6a2b5 --- /dev/null +++ b/src/app/examples/10-inject-token-dependency.spec.ts @@ -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(); +}); diff --git a/src/app/examples/10-inject-token-dependency.ts b/src/app/examples/10-inject-token-dependency.ts new file mode 100644 index 00000000..9a894873 --- /dev/null +++ b/src/app/examples/10-inject-token-dependency.ts @@ -0,0 +1,13 @@ +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 }) {} +}