assertive icon indicating copy to clipboard operation
assertive copied to clipboard

Add support for assert.rejects

Open hybrist opened this issue 10 years ago • 2 comments

This is kind of blurring the lines between assertive and assertive-as-promised, but given async functions this is the only thing I keep "poly-filling". For everything else the normal assertive works perfectly fine:

function assertRejects(promise) {
  return promise.then(() => {
    throw new Error('Did not fail as expected');
  }, error => error);
}

test('foo', async () => {
  const error = await assert.rejects(Promise.reject(new Error('My Error')));
  assert.equal('My Error', error.message);
});

hybrist avatar Nov 07 '15 00:11 hybrist

Great idea! :+1: from me, too. :-) Is its opposite already covered by the other wrapper library? Would be good to have both, IMO. On fre 6 nov. 2015 at 16:57 Jan Olaf Krems [email protected] wrote:

This is kind of blurring the lines between assertive and assertive-as-promised, but given async functions this is the only thing I keep "poly-filling". For everything else the normal assertive works perfectly fine:

function assertRejects(promise) { return promise.then(() => { throw new Error('Did not fail as expected'); }, error => error); } test('foo', async () => { const error = await assert.rejects(Promise.reject(new Error('My Error'))); assert.equal('My Error', error.message); });

— Reply to this email directly or view it on GitHub https://github.com/groupon/assertive/issues/24.

johan avatar Nov 10 '15 18:11 johan

The opposite is already covered by await fnThatRejects(), at least for test frameworks that support promises (e.g. mocha & tap).

hybrist avatar Nov 10 '15 19:11 hybrist