jest expect error code example
Example 1: jest expect error to be thrown
test("Test description", () => {
const t = () => {
throw new TypeError();
};
expect(t).toThrow(TypeError);
});
Example 2: expect any function jest
expect(something).toEqual(expect.any(Function))
Example 3: Jest toContain
# 1. Use '.toContain' when you want to check that an item is in an array.
# 2 '.toContain' can also check whether a string is a substring of another string.
test('the flavor list contains lime', () => {
expect(['lime', 'mangle']).toContain('lime');
});
test('the flavor list contains lime', () => {
expect("lime juice").toContain('lime');
});