.toContain()

This assertion checks an array or string subject contains a value.

values are compared using strict equality

array

jestUnexpected(['a', 'b', 'c', 'd']).toContain('a');
jestUnexpected(['a', 'b', 'c', 'd']).toContain('e');
expected [ 'a''b''c''d' ]
to contain ContainSpec({ spec'e'valueundefinednestedfalse })

If you need structural equality use .toContainEqual():

const something = {};
 
jestUnexpected(['a', something, 'c', 'd']).toContain(something);
const object = { foo: 'bar' };
const other = { foo: 'bar' };
 
jestUnexpected(['a', object, 'c', 'd']).toContain(other);
expected [ 'a', { foo'bar' }, 'c''d' ]
to contain ContainSpec({ spec: { foo'bar' }, valueundefinednestedfalse })

string

jestUnexpected("foo bar").toContain("baz");
expected 'foo bar'
to contain ContainSpec({ spec'baz'valueundefinednestedfalse })
 
foo bar