@@ -22,16 +22,18 @@ import { render, fireEvent, screen } from '../src/public_api';
22
22
} )
23
23
class FixtureComponent { }
24
24
25
- test ( 'creates queries and events' , async ( ) => {
26
- const view = await render ( FixtureComponent ) ;
25
+ describe ( 'DTL functionality' , ( ) => {
26
+ it ( 'creates queries and events' , async ( ) => {
27
+ const view = await render ( FixtureComponent ) ;
27
28
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' ) ) ;
29
+ /// We wish to test the utility function from `render` here.
30
+ // eslint-disable-next-line testing-library/prefer-screen-queries
31
+ fireEvent . input ( view . getByTestId ( 'input' ) , { target : { value : 'a super awesome input' } } ) ;
32
+ // eslint-disable-next-line testing-library/prefer-screen-queries
33
+ expect ( view . getByDisplayValue ( 'a super awesome input' ) ) . toBeInTheDocument ( ) ;
34
+ // eslint-disable-next-line testing-library/prefer-screen-queries
35
+ fireEvent . click ( view . getByText ( 'button' ) ) ;
36
+ } ) ;
35
37
} ) ;
36
38
37
39
describe ( 'standalone' , ( ) => {
@@ -201,13 +203,13 @@ describe('Angular component life-cycle hooks', () => {
201
203
}
202
204
203
205
ngOnChanges ( changes : SimpleChanges ) {
204
- if ( changes . name && this . nameChanged ) {
205
- this . nameChanged ( changes . name . currentValue , changes . name . isFirstChange ( ) ) ;
206
+ if ( this . nameChanged ) {
207
+ this . nameChanged ( changes . name ? .currentValue , changes . name ? .isFirstChange ( ) ) ;
206
208
}
207
209
}
208
210
}
209
211
210
- it ( 'will call ngOnInit on initial render' , async ( ) => {
212
+ it ( 'invokes ngOnInit on initial render' , async ( ) => {
211
213
const nameInitialized = jest . fn ( ) ;
212
214
const componentProperties = { nameInitialized } ;
213
215
const view = await render ( FixtureWithNgOnChangesComponent , { componentProperties } ) ;
@@ -218,7 +220,7 @@ describe('Angular component life-cycle hooks', () => {
218
220
expect ( nameInitialized ) . toHaveBeenCalledWith ( 'Initial' ) ;
219
221
} ) ;
220
222
221
- it ( 'will call ngOnChanges on initial render before ngOnInit' , async ( ) => {
223
+ it ( 'invokes ngOnChanges on initial render before ngOnInit' , async ( ) => {
222
224
const nameInitialized = jest . fn ( ) ;
223
225
const nameChanged = jest . fn ( ) ;
224
226
const componentProperties = { nameInitialized, nameChanged, name : 'Sarah' } ;
@@ -232,6 +234,17 @@ describe('Angular component life-cycle hooks', () => {
232
234
/// expect `nameChanged` to be called before `nameInitialized`
233
235
expect ( nameChanged . mock . invocationCallOrder [ 0 ] ) . toBeLessThan ( nameInitialized . mock . invocationCallOrder [ 0 ] ) ;
234
236
} ) ;
237
+
238
+ it ( 'does not invoke ngOnChanges when no properties are provided' , async ( ) => {
239
+ @Component ( { template : `` } )
240
+ class TestFixtureComponent implements OnChanges {
241
+ ngOnChanges ( ) {
242
+ throw new Error ( 'should not be called' ) ;
243
+ }
244
+ }
245
+
246
+ await render ( TestFixtureComponent ) ;
247
+ } ) ;
235
248
} ) ;
236
249
237
250
test ( 'waits for angular app initialization before rendering components' , async ( ) => {
0 commit comments