// test subjects const rejectsStringValue = () => Promise.reject('I rejected'); const rejectsErrorValue = () => Promise.reject(new Error('I rejected')); // tests describe('rejectsStringValue', () => { it('will throw in try/catch', async () => { expect.assertions(1); try { await rejectsStringValue(); } catch (e) { expect(e).toBe('I rejected'); } }); it('when passing the test-subject as reference', async () => { await expect(rejectsStringValue).rejects.not.toThrow(); await expect(rejectsStringValue).rejects.toMatch('I rejected'); }); it('when executing the test-subject in the expect', async () => { await expect(rejectsStringValue()).rejects.not.toThrow(); await expect(rejectsStringValue()).rejects.toMatch('I rejected'); }); }); describe('rejectsErrorValue', () => { it('will throw in try/catch', async () => { expect.assertions(1); try { await rejectsErrorValue(); } catch (e) { expect(e).toEqual(new Error('I rejected')); } }); it('when passing the test-subject as reference', async () => { await expect(rejectsErrorValue).rejects.toThrow('I rejected'); }); it('when executing the test-subject in the expect', async () => { await expect(rejectsErrorValue()).rejects.toThrow('I rejected'); }); });