File tree Expand file tree Collapse file tree 4 files changed +28
-7
lines changed
projects/ngx-testing-library Expand file tree Collapse file tree 4 files changed +28
-7
lines changed Original file line number Diff line number Diff line change @@ -102,9 +102,9 @@ Runs `detectChanges` on the fixture.
102102
103103The Angular fixture.
104104
105- #### ` get (token: any, notFoundValue?: any) => any`
105+ #### ` getFromTestBed (token: any, notFoundValue?: any) => any`
106106
107- Is the Angular ` TestBed.get ` function.
107+ Calls the the Angular ` TestBed.get ` function.
108108
109109#### ` getComponentInstance(selector?: string) => T `
110110
Original file line number Diff line number Diff line change 11import { Type } from '@angular/core' ;
2+ import { ComponentFixture } from '@angular/core/testing' ;
23
34export interface Result < T > {
4- container : any ;
5- get : ( token : any , notFoundValue ?: any ) => any ;
6- getComponentInstance : < I = T > ( selector ?: string ) => I ;
5+ container : HTMLElement ;
6+ getFromTestBed : ( token : any , notFoundValue ?: any ) => any ;
7+ getComponentInstance : < C = T > ( selector ?: string ) => C ;
78 debug : ( ) => void ;
89 detectChanges : ( checkNoChanges ?: boolean ) => void ;
9- fixture : any ;
10+ fixture : ComponentFixture < any > ;
1011 queryByPlaceholderText : any ;
1112 queryAllByPlaceholderText : any ;
1213 getByPlaceholderText : any ;
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ export async function createComponent<T>(
3838 return {
3939 fixture,
4040 container : fixture . nativeElement ,
41- get : TestBed . get ,
41+ getFromTestBed : TestBed . get ,
4242 getComponentInstance : < C = T > ( selector ?: string ) => {
4343 if ( isTemplate && ! selector ) {
4444 throw new Error ( 'When using the template syntax, you must provide a selector' ) ;
Original file line number Diff line number Diff line change 1+ import { Component , Input , Injectable } from '@angular/core' ;
2+ import { createComponent , fireEvent } from '../src/public_api' ;
3+
4+ @Component ( {
5+ selector : 'fixture' ,
6+ template : `<p>rawr</p> ` ,
7+ } )
8+ class FixtureComponent { }
9+
10+ @Injectable ( )
11+ class FixtureService { }
12+
13+ test ( 'gets TestBed tokens' , async ( ) => {
14+ const { getFromTestBed } = await createComponent ( '<fixture></fixture>' , {
15+ declarations : [ FixtureComponent ] ,
16+ providers : [ FixtureService ] ,
17+ } ) ;
18+
19+ expect ( getFromTestBed ( FixtureService ) ) . toBeDefined ( ) ;
20+ } ) ;
You can’t perform that action at this time.
0 commit comments