File tree Expand file tree Collapse file tree 4 files changed +41
-0
lines changed
Expand file tree Collapse file tree 4 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 4141- ` [jest-config] ` Support ` testTimeout ` in project config ([ #14697 ] ( https://github.com/jestjs/jest/pull/14697 ) )
4242- ` [jest-config] ` Support ` coverageReporters ` in project config ([ #14697 ] ( https://github.com/jestjs/jest/pull/14830 ) )
4343- ` [jest-config] ` Allow ` reporters ` in project config ([ #14768 ] ( https://github.com/jestjs/jest/pull/14768 ) )
44+ - ` [jest-each] ` Allow ` $keypath ` templates with null or undefined values ([ ] ( ) )
4445- ` [@jest/expect-utils] ` Fix comparison of ` DataView ` ([ #14408 ] ( https://github.com/jestjs/jest/pull/14408 ) )
4546- ` [@jest/expect-utils] ` [ ** BREAKING** ] exclude non-enumerable in object matching ([ #14670 ] ( https://github.com/jestjs/jest/pull/14670 ) )
4647- ` [@jest/expect-utils] ` Fix comparison of ` URL ` ([ #14672 ] ( https://github.com/jestjs/jest/pull/14672 ) )
Original file line number Diff line number Diff line change 1+ it . each ( [
2+ { something : { nested : 'value' } } ,
3+ { something : null } ,
4+ { something : undefined } ,
5+ ] ) ( 'allows templating "$something.nested"' , value => {
6+ expect ( value ) . toBe ( value ) ;
7+ } ) ;
8+
9+ it . each ( [ { array : [ 'some value' ] } , { array : null } , { array : undefined } ] ) (
10+ 'allows templating "$array.length"' ,
11+ value => {
12+ expect ( value ) . toBe ( value ) ;
13+ } ,
14+ ) ;
Original file line number Diff line number Diff line change @@ -417,6 +417,30 @@ describe('jest-each', () => {
417417 ) ;
418418 } ) ;
419419
420+ test . each ( [ null , undefined ] ) (
421+ 'calls global with title containing $key.path for %s' ,
422+ value => {
423+ const globalTestMocks = getGlobalTestMocks ( ) ;
424+ const eachObject = each . withGlobal ( globalTestMocks ) `
425+ a
426+ ${ { foo : value } }
427+ ` ;
428+ const testFunction = get ( eachObject , keyPath ) ;
429+ testFunction (
430+ 'interpolates object keyPath to value: $a.foo.bar' ,
431+ noop ,
432+ ) ;
433+
434+ const globalMock = get ( globalTestMocks , keyPath ) ;
435+ expect ( globalMock ) . toHaveBeenCalledTimes ( 1 ) ;
436+ expect ( globalMock ) . toHaveBeenCalledWith (
437+ `interpolates object keyPath to value: ${ value } ` ,
438+ expectFunction ,
439+ undefined ,
440+ ) ;
441+ } ,
442+ ) ;
443+
420444 test ( 'calls global with title containing last seen object when $key.path is invalid' , ( ) => {
421445 const globalTestMocks = getGlobalTestMocks ( ) ;
422446 const eachObject = each . withGlobal ( globalTestMocks ) `
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ export function getPath(
7171 template : Template ,
7272 [ head , ...tail ] : Array < string > ,
7373) : unknown {
74+ if ( template === null ) return 'null' ;
75+ if ( template === undefined ) return 'undefined' ;
7476 if ( ! head || ! Object . prototype . hasOwnProperty . call ( template , head ) )
7577 return template ;
7678 return getPath ( template [ head ] as Template , tail ) ;
You can’t perform that action at this time.
0 commit comments