1
1
import { Component , Injectable , Type , inject } from '@angular/core' ;
2
2
import { TestBed } from '@angular/core/testing' ;
3
3
import { ActivatedRoute } from '@angular/router' ;
4
+ import { ngtx } from '../../ngtx' ;
4
5
import { ScenarioTestingHarness } from '../../scenario-testing/scenario-harnesses' ;
5
6
import { useScenarioTesting } from '../../scenario-testing/scenario-testing' ;
6
7
import { ComponentFixtureRef } from '../../scenario-testing/types' ;
@@ -30,22 +31,23 @@ class ScenarioTestComponent {
30
31
// ----------------------------
31
32
// Test Setup Utilities
32
33
// ----------------------------
33
- const withRouterParams = ( params : Record < string , unknown > ) => ( ) => {
34
- TestBed . overrideProvider ( ActivatedRoute , {
35
- useValue : { snapshot : { params : params } } ,
34
+
35
+ const withRouterParams = ( params : Record < string , unknown > ) =>
36
+ ngtx . scenario . envSetupFn ( ( ) => {
37
+ TestBed . overrideProvider ( ActivatedRoute , {
38
+ useValue : { snapshot : { params : params } } ,
39
+ } ) ;
36
40
} ) ;
37
- } ;
38
41
39
- const withServiceState =
40
- < T > ( token : Type < T > , state : Partial < T > ) =>
41
- ( ) => {
42
+ const withServiceState = < T > ( token : Type < T > , state : Partial < T > ) =>
43
+ ngtx . scenario . envSetupFn ( ( ) => {
42
44
TestBed . overrideProvider ( token , { useValue : state } ) ;
43
- } ;
45
+ } ) ;
44
46
45
47
const withInitialChangeDetection = ( ) => {
46
- return ( fxRef : ComponentFixtureRef ) => {
48
+ return ngtx . scenario . viewSetupFn ( ( fxRef : ComponentFixtureRef ) => {
47
49
fxRef ( ) . changeDetectorRef . detectChanges ( ) ;
48
- } ;
50
+ } ) ;
49
51
} ;
50
52
51
53
// ----------------------------
@@ -66,11 +68,11 @@ class the {
66
68
}
67
69
68
70
scenario ( `MyService value is displayed` )
69
- . configure (
71
+ . setup (
70
72
withRouterParams ( { id : undefined } ) ,
71
73
withServiceState ( MyService , { value : 'Jane' } ) ,
74
+ withInitialChangeDetection ( ) ,
72
75
)
73
- . whenComponentReady ( withInitialChangeDetection ( ) )
74
76
. expect (
75
77
the . Div . toContainText ( 'Jane' ) ,
76
78
the . Div . not . toContainText ( 'Madam' ) ,
@@ -80,10 +82,14 @@ scenario(`MyService value is displayed`)
80
82
color : 'red' ,
81
83
fontSize : '12px' ,
82
84
} ) ,
85
+ the . Div . not . toHaveStyles ( {
86
+ color : 'blue' ,
87
+ fontSize : '24px' ,
88
+ } ) ,
83
89
) ;
84
90
85
91
scenario ( `The param id is 42` )
86
- . configure (
92
+ . setup (
87
93
withRouterParams ( { id : 42 } ) ,
88
94
withServiceState ( MyService , { value : 'Henry' } ) ,
89
95
)
0 commit comments