[RECIPE]: Check error throw in jest

Jest is something which millions of people uses everyday, a lot of questions are answered. But I keep finding something new for me every day.

This is not gonna work:

describe('throw test', () => {
    it('should throw the error', () => {
        expect(throwingFunc()).toThrow();
    });
});

Test will fail with the error you are looking for.

But this will do the trick:

describe('throw test', () => {
    it('should throw the error', () => {
        expect(() => throwingFunc()).toThrow();
    });
});

The only difference is the usage of arrow function.

Write readable, simple and meaningful tests!