Skip to content

Commit ad2430c

Browse files
committed
feat: rename get to getFromTestBed
1 parent 56587f9 commit ad2430c

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ Runs `detectChanges` on the fixture.
102102

103103
The 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

projects/ngx-testing-library/src/lib/models.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { Type } from '@angular/core';
2+
import { ComponentFixture } from '@angular/core/testing';
23

34
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;
78
debug: () => void;
89
detectChanges: (checkNoChanges?: boolean) => void;
9-
fixture: any;
10+
fixture: ComponentFixture<any>;
1011
queryByPlaceholderText: any;
1112
queryAllByPlaceholderText: any;
1213
getByPlaceholderText: any;

projects/ngx-testing-library/src/lib/ngx-testing-library.ts

+1-1
Original file line numberDiff line numberDiff 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 numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
});

0 commit comments

Comments
 (0)