jest-chain icon indicating copy to clipboard operation
jest-chain copied to clipboard

Support promises and returning matcher from test

Open dobesv opened this issue 6 years ago β€’ 10 comments

What

Feature: support async returns from matchers

Why

If you want to use jest-chain and you also need to return a Promise from your test function. Without this change, jest-chain will throw away all the promises.

Notes

This makes jest-chain always return a promise. The promise also has all the matchers available on it. If a matcher in the chain returns a promise, the promise returned by chained matchers will depend on that promise.

Housekeeping

  • [x] Unit tests
  • [x] Documentation is up to date
  • [x] No additional lint warnings

dobesv avatar Oct 23 '19 23:10 dobesv

Codecov Report

Merging #11 into master will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #11   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines           23        24    +1     
  Branches         3         4    +1     
=========================================
+ Hits            23        24    +1     
Impacted Files Coverage Ξ”
src/chain.js 100.00% <100.00%> (ΓΈ)

Continue to review full report at Codecov.

Legend - Click here to learn more Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data Powered by Codecov. Last update dde0129...6828dcc. Read the comment docs.

codecov-io avatar Oct 23 '19 23:10 codecov-io

May supersede https://github.com/mattphillips/jest-chain/pull/9

dobesv avatar Oct 23 '19 23:10 dobesv

Fixes https://github.com/mattphillips/jest-chain/issues/8

dobesv avatar Oct 23 '19 23:10 dobesv

Fixes https://github.com/mattphillips/jest-chain/issues/1

dobesv avatar Oct 23 '19 23:10 dobesv

@mattphillips I resolved the conflicts, in case you were waiting for that. Let me know if there's anything else I can do to move this one forwards.

dobesv avatar Jan 31 '20 22:01 dobesv

ey, @mattphillips, is it going to be merged? :+1:

tonivj5 avatar Mar 03 '20 19:03 tonivj5

I've also updated the typing to reflect that rejects and resolves return a promise that also has matchers on it.

dobesv avatar Apr 30 '20 05:04 dobesv

/cc @mattphillips

RA80533 avatar Sep 01 '20 04:09 RA80533

Would love to see this merged. Thank you @dobesv for your work on this.

sepehr avatar Nov 17 '20 11:11 sepehr

@mattphillips is it possible to merge that priceless PR?

twawszczak-wr avatar Dec 07 '20 17:12 twawszczak-wr

Sorry for the delay in coming to this! The promises issue has been fixed in: https://www.npmjs.com/package/jest-chain/v/1.1.6

As for returning chained matchers (synchronous ones) inside of a promise to allow returning expect I'm not too sure this is a good idea and if it will cause existing tests to break so have for now chosen not to support this as it deviates from Jests behaviour.

I've added a skipped test for this for future reference https://github.com/mattphillips/jest-chain/blob/da5a0e0e5d19668cf8b24a6e84168beba37855b0/src/index.test.js#L56

mattphillips avatar Sep 28 '22 17:09 mattphillips