fix: improve asymmetric matcher diff readability by unwrapping contai… · vitest-dev/vitest@b2ec724

@@ -142,7 +142,7 @@ test('asymmetric matcher in object', () => {

142142

{

143143

- "x": 1,

144144

+ "x": 0,

145-

"y": Anything,

145+

"y": "foo",

146146

}"

147147

`)

148148

})

@@ -159,7 +159,7 @@ test('asymmetric matcher in object with truncated diff', () => {

159159

+ Received

160160161161

{

162-

"w": Anything,

162+

"w": "foo",

163163

- "x": 1,

164164

+ "x": 0,

165165

... Diff result is truncated"

@@ -174,7 +174,7 @@ test('asymmetric matcher in array', () => {

174174

[

175175

- 1,

176176

+ 0,

177-

Anything,

177+

"foo",

178178

]"

179179

`)

180180

})

@@ -211,12 +211,12 @@ test('asymmetric matcher in nested', () => {

211211

{

212212

- "x": 1,

213213

+ "x": 0,

214-

"y": Anything,

214+

"y": "foo",

215215

},

216216

[

217217

- 1,

218218

+ 0,

219-

Anything,

219+

"bar",

220220

],

221221

]"

222222

`)

@@ -237,8 +237,8 @@ test('asymmetric matcher in nested with truncated diff', () => {

237237

{

238238

- "x": 1,

239239

+ "x": 0,

240-

"y": Anything,

241-

"z": Anything,

240+

"y": "foo",

241+

"z": "bar",

242242

... Diff result is truncated"

243243

`)

244244

})

@@ -353,3 +353,136 @@ function getErrorDiff(actual: unknown, expected: unknown, options?: DiffOptions)

353353

}

354354

return expect.unreachable()

355355

}

356+357+

test('asymmetric matcher with objectContaining - simple case', () => {

358+

const actual = {

359+

user: {

360+

name: 'John',

361+

age: 25,

362+

email: 'john@example.com',

363+

},

364+

}

365+366+

const expected = {

367+

user: expect.objectContaining({

368+

name: expect.stringContaining('Jane'),

369+

age: expect.any(Number),

370+

email: expect.stringContaining('example.com'),

371+

}),

372+

}

373+374+

expect(stripVTControlCharacters(getErrorDiff(actual, expected))).toMatchInlineSnapshot(`

375+

"- Expected

376+

+ Received

377+378+

{

379+

"user": {

380+

"age": 25,

381+

"email": "john@example.com",

382+

- "name": StringContaining "Jane",

383+

+ "name": "John",

384+

},

385+

}"

386+

`)

387+

})

388+389+

test('asymmetric matcher with nested objectContaining and arrayContaining', () => {

390+

const actual = {

391+

model: 'veo-3.1-generate-preview',

392+

instances: [

393+

{

394+

prompt: 'walk',

395+

referenceImages: [

396+

{

397+

image: {

398+

gcsUri: 'gs://example/person1.jpg',

399+

mimeType: 'image/png',

400+

},

401+

referenceType: 'asset',

402+

},

403+

{

404+

image: {

405+

gcsUri: 'gs://example/person.jpg',

406+

mimeType: 'image/png',

407+

},

408+

referenceType: 'asset',

409+

},

410+

],

411+

},

412+

],

413+

parameters: {

414+

durationSeconds: '8',

415+

aspectRatio: '16:9',

416+

generateAudio: true,

417+

},

418+

}

419+420+

const expected = {

421+

model: expect.stringMatching(/^veo-3\.1-(fast-)?generate-preview$/),

422+

instances: expect.arrayContaining([

423+

expect.objectContaining({

424+

prompt: expect.stringMatching(/^(?=.*walking)(?=.*together)(?=.*park).*/i),

425+

referenceImages: expect.arrayContaining([

426+

expect.objectContaining({

427+

image: expect.objectContaining({

428+

gcsUri: expect.stringContaining('person1.jpg'),

429+

mimeType: 'image/jpeg',

430+

}),

431+

referenceType: expect.stringMatching(/^(asset|style)$/),

432+

}),

433+

expect.objectContaining({

434+

image: expect.objectContaining({

435+

gcsUri: expect.stringContaining('person2.png'),

436+

mimeType: 'image/png',

437+

}),

438+

referenceType: expect.stringMatching(/^(asset|style)$/),

439+

}),

440+

]),

441+

}),

442+

]),

443+

parameters: expect.objectContaining({

444+

durationSeconds: expect.any(Number),

445+

aspectRatio: '16:9',

446+

generateAudio: expect.any(Boolean),

447+

}),

448+

}

449+450+

expect(stripVTControlCharacters(getErrorDiff(actual, expected))).toMatchInlineSnapshot(`

451+

"- Expected

452+

+ Received

453+454+

{

455+

"instances": [

456+

{

457+

- "prompt": StringMatching /^(?=.*walking)(?=.*together)(?=.*park).*/i,

458+

+ "prompt": "walk",

459+

"referenceImages": [

460+

{

461+

"image": {

462+

"gcsUri": "gs://example/person1.jpg",

463+

- "mimeType": "image/jpeg",

464+

+ "mimeType": "image/png",

465+

},

466+

"referenceType": "asset",

467+

},

468+

{

469+

"image": {

470+

- "gcsUri": StringContaining "person2.png",

471+

+ "gcsUri": "gs://example/person.jpg",

472+

"mimeType": "image/png",

473+

},

474+

"referenceType": "asset",

475+

},

476+

],

477+

},

478+

],

479+

"model": "veo-3.1-generate-preview",

480+

"parameters": {

481+

"aspectRatio": "16:9",

482+

- "durationSeconds": Any<Number>,

483+

+ "durationSeconds": "8",

484+

"generateAudio": true,

485+

},

486+

}"

487+

`)

488+

})