@@ -151,14 +151,14 @@ describe('parse', () => {
151151} ) ;
152152describe ( 'getSnapshotContent' , ( ) => {
153153 it . each `
154- testName | expected
155- ${ 'regular inline test' } | ${ undefined }
156- ${ 'test.each %s' } | ${ undefined }
157- ${ 'test.each a' } | ${ 'a' }
158- ${ '1 describe with each test.each a' } | ${ '1.a' }
159- ${ '2 describe with each test.each b' } | ${ '2.b' }
160- ${ 'tests with each case %d test 1-D array each' } | ${ undefined }
161- ${ 'tests with each case 3 test 1-D array each' } | ${ '3 1-D' }
154+ testName | expected
155+ ${ 'regular inline test 1 ' } | ${ undefined }
156+ ${ 'test.each %s 1 ' } | ${ undefined }
157+ ${ 'test.each a 1 ' } | ${ 'a' }
158+ ${ '1 describe with each test.each a 1 ' } | ${ '1.a' }
159+ ${ '2 describe with each test.each b 1 ' } | ${ '2.b' }
160+ ${ 'tests with each case %d test 1-D array each 1 ' } | ${ undefined }
161+ ${ 'tests with each case 3 test 1-D array each 1 ' } | ${ '3 1-D' }
162162 ` ( '' , async ( { testName, expected} ) => {
163163 const filePath = path . join ( snapshotFixturePath , 'inline-and-each.example' ) ;
164164 const snapshot = new Snapshot ( undefined , [ 'toMatchInlineSnapshot' , 'toThrowErrorMatchingInlineSnapshot' ] ) ;
@@ -168,9 +168,22 @@ describe('getSnapshotContent', () => {
168168 it ( 'can take literal snapshot name' , async ( ) => {
169169 const filePath = path . join ( snapshotFixturePath , 'inline-and-each.example' ) ;
170170 const snapshot = new Snapshot ( undefined , [ 'toMatchInlineSnapshot' , 'toThrowErrorMatchingInlineSnapshot' ] ) ;
171- let content = await snapshot . getSnapshotContent ( filePath , `literal test 2` ) ;
172- expect ( content ) . toBeUndefined ( ) ;
173- content = await snapshot . getSnapshotContent ( filePath , `literal test 2` , false ) ;
171+ const content = await snapshot . getSnapshotContent ( filePath , `literal test 2` ) ;
174172 expect ( content ) . toEqual ( 'literal test 2 content' ) ;
175173 } ) ;
174+ it ( 'can take regex' , async ( ) => {
175+ const filePath = path . join ( snapshotFixturePath , 'inline-and-each.example' ) ;
176+ const snapshot = new Snapshot ( undefined , [ 'toMatchInlineSnapshot' , 'toThrowErrorMatchingInlineSnapshot' ] ) ;
177+ const content = await snapshot . getSnapshotContent ( filePath , / l i t e r a l t e s t / ) ;
178+ expect ( content ) . toEqual ( {
179+ 'literal test 1' : 'literal test 1 content' ,
180+ 'literal test 2' : 'literal test 2 content' ,
181+ } ) ;
182+ } ) ;
183+ it ( 'if nothing matched, returns null' , async ( ) => {
184+ const filePath = path . join ( snapshotFixturePath , 'inline-and-each.example' ) ;
185+ const snapshot = new Snapshot ( undefined , [ 'toMatchInlineSnapshot' , 'toThrowErrorMatchingInlineSnapshot' ] ) ;
186+ const content = await snapshot . getSnapshotContent ( filePath , / n o t e x i s t i n g t e s t / ) ;
187+ expect ( content ) . toEqual ( null ) ;
188+ } ) ;
176189} ) ;
0 commit comments