l2beat / earl

☕ Ergonomic, modern and type-safe assertion library for TypeScript
https://earl.fun/
MIT License
256 stars 19 forks source link

Feature request: toThrow() / toBeRejected() should return the objects thrown / rejected with #289

Open dhardtke opened 11 months ago

dhardtke commented 11 months ago

It would be neat if we could do the following:

const rejectedWith = await expect(Promise.reject(new CustomError('foo', {myProp: 42, count: 2})))
  .toBeRejectedWith(CustomError) as CustomError;
expect(rejectedWith.myProp).toEqual(42);
expect(rejectedWith.count).toBeGreaterThan(1);

The same is true for toThrow().