@@ -21,16 +21,18 @@ import { render, fireEvent, screen } from '../src/public_api';
21
21
} )
22
22
class FixtureComponent { }
23
23
24
- test ( 'creates queries and events' , async ( ) => {
25
- const view = await render ( FixtureComponent ) ;
24
+ describe ( 'DTL functionality' , ( ) => {
25
+ it ( 'creates queries and events' , async ( ) => {
26
+ const view = await render ( FixtureComponent ) ;
26
27
27
- /// We wish to test the utility function from `render` here.
28
- // eslint-disable-next-line testing-library/prefer-screen-queries
29
- fireEvent . input ( view . getByTestId ( 'input' ) , { target : { value : 'a super awesome input' } } ) ;
30
- // eslint-disable-next-line testing-library/prefer-screen-queries
31
- expect ( view . getByDisplayValue ( 'a super awesome input' ) ) . toBeInTheDocument ( ) ;
32
- // eslint-disable-next-line testing-library/prefer-screen-queries
33
- fireEvent . click ( view . getByText ( 'button' ) ) ;
28
+ /// We wish to test the utility function from `render` here.
29
+ // eslint-disable-next-line testing-library/prefer-screen-queries
30
+ fireEvent . input ( view . getByTestId ( 'input' ) , { target : { value : 'a super awesome input' } } ) ;
31
+ // eslint-disable-next-line testing-library/prefer-screen-queries
32
+ expect ( view . getByDisplayValue ( 'a super awesome input' ) ) . toBeInTheDocument ( ) ;
33
+ // eslint-disable-next-line testing-library/prefer-screen-queries
34
+ fireEvent . click ( view . getByText ( 'button' ) ) ;
35
+ } ) ;
34
36
} ) ;
35
37
36
38
describe ( 'standalone' , ( ) => {
@@ -162,13 +164,13 @@ describe('Angular component life-cycle hooks', () => {
162
164
}
163
165
164
166
ngOnChanges ( changes : SimpleChanges ) {
165
- if ( changes . name && this . nameChanged ) {
166
- this . nameChanged ( changes . name . currentValue , changes . name . isFirstChange ( ) ) ;
167
+ if ( this . nameChanged ) {
168
+ this . nameChanged ( changes . name ? .currentValue , changes . name ? .isFirstChange ( ) ) ;
167
169
}
168
170
}
169
171
}
170
172
171
- it ( 'will call ngOnInit on initial render' , async ( ) => {
173
+ it ( 'invokes ngOnInit on initial render' , async ( ) => {
172
174
const nameInitialized = jest . fn ( ) ;
173
175
const componentProperties = { nameInitialized } ;
174
176
const view = await render ( FixtureWithNgOnChangesComponent , { componentProperties } ) ;
@@ -179,7 +181,7 @@ describe('Angular component life-cycle hooks', () => {
179
181
expect ( nameInitialized ) . toHaveBeenCalledWith ( 'Initial' ) ;
180
182
} ) ;
181
183
182
- it ( 'will call ngOnChanges on initial render before ngOnInit' , async ( ) => {
184
+ it ( 'invokes ngOnChanges on initial render before ngOnInit' , async ( ) => {
183
185
const nameInitialized = jest . fn ( ) ;
184
186
const nameChanged = jest . fn ( ) ;
185
187
const componentProperties = { nameInitialized, nameChanged, name : 'Sarah' } ;
@@ -193,6 +195,17 @@ describe('Angular component life-cycle hooks', () => {
193
195
/// expect `nameChanged` to be called before `nameInitialized`
194
196
expect ( nameChanged . mock . invocationCallOrder [ 0 ] ) . toBeLessThan ( nameInitialized . mock . invocationCallOrder [ 0 ] ) ;
195
197
} ) ;
198
+
199
+ it ( 'does not invoke ngOnChanges when no properties are provided' , async ( ) => {
200
+ @Component ( { template : `` } )
201
+ class TestFixtureComponent implements OnChanges {
202
+ ngOnChanges ( ) {
203
+ throw new Error ( 'should not be called' ) ;
204
+ }
205
+ }
206
+
207
+ await render ( TestFixtureComponent ) ;
208
+ } ) ;
196
209
} ) ;
197
210
198
211
test ( 'waits for angular app initialization before rendering components' , async ( ) => {
0 commit comments