iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🍣
How to Perform Partial Object Matching in Jest
Goal
Checking if
{
"id": 1,
"name": "taro",
"age": 10
}
contains
{
"name": "taro",
"age": 10
}
How to do it
Use expect.objectContaining!
const obj = {
id: 1,
name: "taro",
age: 10,
};
expect(obj).toEqual(
expect.objectContaining({
name: "taro",
age: 10,
})
);
refs
https://www.366service.com/jp/qa/0b876bbb520062cbe621d6e6599521fb
Discussion