---
type: snippet
tags: ['test', 'jest']
status: release
ctime: 2025-01-18
mtime: 2026-08-02
---

https://www.emgoto.com/jest-partial-match/

`objectContaining`·`arrayContaining` 은 `toEqual`·`toHaveBeenCalledWith` 안에 중첩해서 쓴다.

```typescript
test('호출 인자 부분 매칭', () => {
  const mockFunction = jest.fn()

  mockFunction({ id: 1, name: 'Alice', tags: ['developer', 'designer'] })

  expect(mockFunction).toHaveBeenCalledWith(
    expect.objectContaining({
      name: 'Alice',
      tags: expect.arrayContaining(['designer']),
    })
  )
})

test('배열 안 객체 부분 매칭', () => {
  const receivedArray = [
    { id: 1, name: 'Alice' },
    { id: 2, name: 'Bob' },
  ]

  expect(receivedArray).toEqual(
    expect.arrayContaining([
      expect.objectContaining({ name: 'Alice' }),
      expect.objectContaining({ id: 2 }),
    ])
  )
})
```
