Object
.toBeEmptyObject()
Use .toBeEmptyObject
when checking if a value is an empty Object
.
test('passes when value is an empty object', () => { expect({}).toBeEmptyObject(); expect({ a: 'hello' }).not.toBeEmptyObject(); });
Tests
.toBeObject()
Use .toBeObject
when checking if a value is an Object
.
test('passes when value is an object', () => { expect({}).toBeObject(); expect({ a: 'hello' }).toBeObject(); expect(true).not.toBeObject(); });
Tests
.toContainKey(key)
Use .toContainKey
when checking if an object contains the provided key.
test('passes when object contains the given key', () => { const o = { a: 'foo', b: 'bar', c: 'baz' }; expect(o).toContainKey('a'); expect(o).toContainKey('b'); expect(o).toContainKey('c'); expect(o).not.toContainKey('d'); });
Tests
.toContainKeys([keys])
Use .toContainKeys
when checking if an object has all of the provided keys.
test('passes when object contains all keys', () => { const o = { a: 'foo', b: 'bar', c: 'baz' }; expect(o).toContainKeys(['a', 'b']); expect(o).toContainKeys(['b', 'c']); expect(o).not.toContainKeys(['d']); });
Tests
.toContainAllKeys([keys])
Use .toContainAllKeys
when checking if an object only contains all of the provided keys.
test('passes when object only contains all keys', () => { const o = { a: 'hello', b: 'world' }; expect(o).toContainAllKeys(['a', 'b']); expect(o).toContainAllKeys(['b', 'a']); expect(o).not.toContainAllKeys(['b']); });
Tests
.toContainAnyKeys([keys])
Use .toContainAnyKeys
when checking if an object contains at least one of the provided keys.
test('passes when object contains at least one matching key', () => { const o = { a: 'hello', b: 'world' }; expect(o).toContainAnyKeys(['a']); expect(o).toContainAnyKeys(['b']); expect(o).toContainAnyKeys(['b', 'c']); expect(o).not.toContainAnyKeys(['c']); });
Tests
.toContainValue(value)
Use .toContainValue
when checking if an object contains the provided value.
test('passes when object contains given value', () => { const o = { a: 'foo', b: 'bar', c: 'baz' }; expect(o).toContainValue('foo'); expect(o).toContainValue('bar'); expect(o).not.toContainValue('qux'); });
Tests
.toContainValues([values])
Use .toContainValues
when checking if an object contains all of the provided values.
test('passes when object contains all of the given values', () => { const o = { a: 'foo', b: 'bar', c: 'baz' }; expect(o).toContainValues(['foo']); expect(o).toContainValues(['baz', 'bar']); expect(o).not.toContainValues(['qux', 'foo']); });
Tests
.toContainAllValues([values])
Use .toContainAllValues
when checking if an object only contains all of the provided values.
test('passes when object only contains all of the given values', () => { const o = { a: 'foo', b: 'bar', c: 'baz' }; expect(o).toContainAllValues(['foo', 'bar', 'baz']); expect(o).toContainAllValues(['baz', 'bar', 'foo']); expect(o).not.toContainAllValues(['bar', 'foo']); });
Tests
.toContainAnyValues([values])
Use .toContainAnyValues
when checking if an object contains at least one of the provided values.
test('passes when object contains at least one of the given values', () => { const o = { a: 'foo', b: 'bar', c: 'baz' }; expect(o).toContainAnyValues(['qux', 'foo']); expect(o).toContainAnyValues(['qux', 'bar']); expect(o).toContainAnyValues(['qux', 'baz']); expect(o).not.toContainAnyValues(['qux']); });
Tests
.toContainEntry([key, value])
Use .toContainEntry
when checking if an object contains the provided entry.
test('passes when object contains given entry', () => { const o = { a: 'foo', b: 'bar', c: 'baz' }; expect(o).toContainEntry(['a', 'foo']); expect(o).toContainEntry(['b', 'bar']); expect(o).toContainEntry(['c', 'baz']); expect(o).not.toContainEntry(['a', 'qux']); });
Tests
.toContainEntries([[key, value]])
Use .toContainEntries
when checking if an object contains all of the provided entries.
test('passes when object contains all of the given entries', () => { const o = { a: 'foo', b: 'bar', c: 'baz' }; expect(o).toContainEntries([['a', 'foo']]); expect(o).toContainEntries([ ['c', 'baz'], ['a', 'foo'], ]); expect(o).not.toContainEntries([ ['b', 'qux'], ['a', 'foo'], ]); });
Tests
.toContainAllEntries([[key, value]])
Use .toContainAllEntries
when checking if an object only contains all of the provided entries.
test('passes when object only contains all of the given entries', () => { const o = { a: 'foo', b: 'bar', c: 'baz' }; expect(o).toContainAllEntries([ ['a', 'foo'], ['b', 'bar'], ['c', 'baz'], ]); expect(o).not.toContainAllEntries([ ['a', 'foo'], ['b', 'bar'], ]); });
Tests
.toContainAnyEntries([[key, value]])
Use .toContainAnyEntries
when checking if an object contains at least one of the provided entries.
test('passes when object contains at least one of the given entries', () => { const o = { a: 'foo', b: 'bar', c: 'baz' }; expect(o).toContainAnyEntries([ ['a', 'qux'], ['a', 'foo'], ]); expect(o).toContainAnyEntries([ ['a', 'qux'], ['b', 'bar'], ]); expect(o).toContainAnyEntries([ ['a', 'qux'], ['c', 'baz'], ]); expect(o).not.toContainAnyEntries([['d', 'qux']]); });
Tests
.toBeExtensible()
Use .toBeExtensible
when checking if an object is extensible.
test('passes when value is extensible', () => { expect({ a: 1 }).toBeExtensible(); expect(1).not.toBeExtensible(); });
Tests
.toBeFrozen()
Use .toBeFrozen
when checking if an object is frozen.
test('passes when value is frozen', () => { expect(Object.freeze({})).toBeFrozen(); expect({}).not.toBeFrozen(); });
Tests
.toBeSealed()
Use .toBeSealed
when checking if an object is sealed.
test('passes when value is sealed', () => { expect(Object.seal({})).toBeSealed(); expect({}).not.toBeSealed(); });
Tests