Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 662f135

Browse files
fix: add providers to configureTestingModule (testing-library#22)
1 parent 7f1dce6 commit 662f135

File tree

6 files changed

+26
-13
lines changed

6 files changed

+26
-13
lines changed

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"@angular/platform-browser": "^8.0.0",
3535
"@angular/platform-browser-dynamic": "^8.0.0",
3636
"@angular/router": "^8.0.0",
37+
"@ngrx/store": "^8.0.0-rc.0",
3738
"@phenomnomnominal/tsquery": "^3.0.0",
3839
"@testing-library/dom": "^5.0.1",
3940
"core-js": "^3.1.3",

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@ export async function render<T>(
3232
TestBed.configureTestingModule({
3333
declarations: [...declarations, ...componentDeclarations],
3434
imports: [...imports],
35+
providers: [...providers],
3536
schemas: [...schemas],
3637
});
3738

3839
if (providers) {
3940
// override services this way to have the service overridden at the component level
40-
providers.forEach(p => {
41-
const { provide, ...provider } = p;
42-
TestBed.overrideProvider(provide, provider);
43-
});
41+
providers
42+
.reduce((acc, provider) => acc.concat(provider), [])
43+
.forEach(p => {
44+
const { provide, ...provider } = p;
45+
TestBed.overrideProvider(provide, provider);
46+
});
4447
}
4548

4649
const fixture = isTemplate

‎src/app/app.component.spec.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
11
import { AppComponent } from './app.component';
22
import { render } from '@testing-library/angular';
33
import { configureJestSetup } from '@testing-library/angular/jest-utils';
4+
import { provideMockStore } from '@ngrx/store/testing';
45

56
configureJestSetup();
67

78
test(`matches snapshot`, async () => {
89
const { container } = await render('<app-root></app-root>', {
910
declarations: [AppComponent],
11+
providers: [provideMockStore()],
1012
});
1113
expect(container).toMatchSnapshot();
1214
});
1315

1416
test(`should have a title`, async () => {
1517
const { getByText } = await render('<app-root></app-root>', {
1618
declarations: [AppComponent],
19+
providers: [provideMockStore()],
1720
});
1821
expect(getByText('Welcome to app!')).toBeDefined();
1922
});
2023

2124
test(`should render title in a h1 tag`, async () => {
2225
const { container } = await render('<app-root></app-root>', {
2326
declarations: [AppComponent],
27+
providers: [provideMockStore()],
2428
});
2529
expect(container.querySelector('h1').textContent).toContain('Welcome to app!');
2630
});

‎src/app/app.component.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { Component } from '@angular/core';
2+
import { Store } from '@ngrx/store';
23

34
@Component({
45
selector: 'app-root',
56
templateUrl: './app.component.html',
6-
styleUrls: ['./app.component.css']
7+
styleUrls: ['./app.component.css'],
78
})
89
export class AppComponent {
910
title = 'app';
11+
12+
constructor(private store: Store<any>) {}
1013
}

‎src/app/app.module.ts‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import { BrowserModule } from '@angular/platform-browser';
22
import { NgModule } from '@angular/core';
33

44
import { AppComponent } from './app.component';
5+
import { StoreModule } from '@ngrx/store';
56

67
@NgModule({
7-
declarations: [
8-
AppComponent
9-
],
10-
imports: [
11-
BrowserModule
12-
],
8+
declarations: [AppComponent],
9+
imports: [BrowserModule, StoreModule.forRoot({})],
1310
providers: [],
14-
bootstrap: [AppComponent]
11+
bootstrap: [AppComponent],
1512
})
16-
export class AppModule {}
13+
export class AppModule {}

‎yarn.lock‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,11 @@
511511
call-me-maybe "^1.0.1"
512512
glob-to-regexp "^0.3.0"
513513

514+
"@ngrx/store@^8.0.0-rc.0":
515+
version "8.0.0-rc.0"
516+
resolved "https://registry.yarnpkg.com/@ngrx/store/-/store-8.0.0-rc.0.tgz#3ec0ca8986fb3cb2b246cab0c851833a21f9a134"
517+
integrity sha512-TL+2BERGH4DET8sIW1D02wkmKxlnVXWezm1OkQJd2Q/6h6MwZBd8SeDpuiEIUHr2/1BPUyPNe1bj+vemeiwWrw==
518+
514519
"@ngtools/json-schema@^1.1.0":
515520
version "1.1.0"
516521
resolved "https://registry.yarnpkg.com/@ngtools/json-schema/-/json-schema-1.1.0.tgz#c3a0c544d62392acc2813a42c8a0dc6f58f86922"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /