File tree 6 files changed +26
-13
lines changed
projects/testing-library/src/lib
6 files changed +26
-13
lines changed Original file line number Diff line number Diff line change 34
34
"@angular/platform-browser" : " ^8.0.0" ,
35
35
"@angular/platform-browser-dynamic" : " ^8.0.0" ,
36
36
"@angular/router" : " ^8.0.0" ,
37
+ "@ngrx/store" : " ^8.0.0-rc.0" ,
37
38
"@phenomnomnominal/tsquery" : " ^3.0.0" ,
38
39
"@testing-library/dom" : " ^5.0.1" ,
39
40
"core-js" : " ^3.1.3" ,
Original file line number Diff line number Diff line change @@ -32,15 +32,18 @@ export async function render<T>(
32
32
TestBed . configureTestingModule ( {
33
33
declarations : [ ...declarations , ...componentDeclarations ] ,
34
34
imports : [ ...imports ] ,
35
+ providers : [ ...providers ] ,
35
36
schemas : [ ...schemas ] ,
36
37
} ) ;
37
38
38
39
if ( providers ) {
39
40
// 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
+ } ) ;
44
47
}
45
48
46
49
const fixture = isTemplate
Original file line number Diff line number Diff line change 1
1
import { AppComponent } from './app.component' ;
2
2
import { render } from '@testing-library/angular' ;
3
3
import { configureJestSetup } from '@testing-library/angular/jest-utils' ;
4
+ import { provideMockStore } from '@ngrx/store/testing' ;
4
5
5
6
configureJestSetup ( ) ;
6
7
7
8
test ( `matches snapshot` , async ( ) => {
8
9
const { container } = await render ( '<app-root></app-root>' , {
9
10
declarations : [ AppComponent ] ,
11
+ providers : [ provideMockStore ( ) ] ,
10
12
} ) ;
11
13
expect ( container ) . toMatchSnapshot ( ) ;
12
14
} ) ;
13
15
14
16
test ( `should have a title` , async ( ) => {
15
17
const { getByText } = await render ( '<app-root></app-root>' , {
16
18
declarations : [ AppComponent ] ,
19
+ providers : [ provideMockStore ( ) ] ,
17
20
} ) ;
18
21
expect ( getByText ( 'Welcome to app!' ) ) . toBeDefined ( ) ;
19
22
} ) ;
20
23
21
24
test ( `should render title in a h1 tag` , async ( ) => {
22
25
const { container } = await render ( '<app-root></app-root>' , {
23
26
declarations : [ AppComponent ] ,
27
+ providers : [ provideMockStore ( ) ] ,
24
28
} ) ;
25
29
expect ( container . querySelector ( 'h1' ) . textContent ) . toContain ( 'Welcome to app!' ) ;
26
30
} ) ;
Original file line number Diff line number Diff line change 1
1
import { Component } from '@angular/core' ;
2
+ import { Store } from '@ngrx/store' ;
2
3
3
4
@Component ( {
4
5
selector : 'app-root' ,
5
6
templateUrl : './app.component.html' ,
6
- styleUrls : [ './app.component.css' ]
7
+ styleUrls : [ './app.component.css' ] ,
7
8
} )
8
9
export class AppComponent {
9
10
title = 'app' ;
11
+
12
+ constructor ( private store : Store < any > ) { }
10
13
}
Original file line number Diff line number Diff line change @@ -2,15 +2,12 @@ import { BrowserModule } from '@angular/platform-browser';
2
2
import { NgModule } from '@angular/core' ;
3
3
4
4
import { AppComponent } from './app.component' ;
5
+ import { StoreModule } from '@ngrx/store' ;
5
6
6
7
@NgModule ( {
7
- declarations : [
8
- AppComponent
9
- ] ,
10
- imports : [
11
- BrowserModule
12
- ] ,
8
+ declarations : [ AppComponent ] ,
9
+ imports : [ BrowserModule , StoreModule . forRoot ( { } ) ] ,
13
10
providers : [ ] ,
14
- bootstrap : [ AppComponent ]
11
+ bootstrap : [ AppComponent ] ,
15
12
} )
16
- export class AppModule { }
13
+ export class AppModule { }
Original file line number Diff line number Diff line change 511
511
call-me-maybe "^1.0.1"
512
512
glob-to-regexp "^0.3.0"
513
513
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
+
514
519
" @ngtools/json-schema@^1.1.0 " :
515
520
version "1.1.0"
516
521
resolved "https://registry.yarnpkg.com/@ngtools/json-schema/-/json-schema-1.1.0.tgz#c3a0c544d62392acc2813a42c8a0dc6f58f86922"
You can’t perform that action at this time.
0 commit comments