groupon / assertive

Assertive is a terse yet expressive assertion library
BSD 3-Clause "New" or "Revised" License
21 stars 11 forks source link

Add support for assert.rejects #24

Open jkrems opened 8 years ago

jkrems commented 8 years ago

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);
});
johan commented 8 years ago

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 notifications@github.com 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.

jkrems commented 8 years ago

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