File tree 4 files changed +28
-7
lines changed
projects/ngx-testing-library
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.
102
102
103
103
The Angular fixture.
104
104
105
- #### ` get (token: any, notFoundValue?: any) => any`
105
+ #### ` getFromTestBed (token: any, notFoundValue?: any) => any`
106
106
107
- Is the Angular ` TestBed.get ` function.
107
+ Calls the the Angular ` TestBed.get ` function.
108
108
109
109
#### ` getComponentInstance(selector?: string) => T `
110
110
Original file line number Diff line number Diff line change 1
1
import { Type } from '@angular/core' ;
2
+ import { ComponentFixture } from '@angular/core/testing' ;
2
3
3
4
export 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 ;
7
8
debug : ( ) => void ;
8
9
detectChanges : ( checkNoChanges ?: boolean ) => void ;
9
- fixture : any ;
10
+ fixture : ComponentFixture < any > ;
10
11
queryByPlaceholderText : any ;
11
12
queryAllByPlaceholderText : any ;
12
13
getByPlaceholderText : any ;
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ export async function createComponent<T>(
38
38
return {
39
39
fixture,
40
40
container : fixture . nativeElement ,
41
- get : TestBed . get ,
41
+ getFromTestBed : TestBed . get ,
42
42
getComponentInstance : < C = T > ( selector ?: string ) => {
43
43
if ( isTemplate && ! selector ) {
44
44
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