Skip to content

Instantly share code, notes, and snippets.

@RA80533
Created November 12, 2020 20:30
Show Gist options
  • Save RA80533/521b3442d9df0ecfdd67af5a842b415d to your computer and use it in GitHub Desktop.
Save RA80533/521b3442d9df0ecfdd67af5a842b415d to your computer and use it in GitHub Desktop.
Patch for jest-chain which fixes several outstanding issues including Promise support and error propagation
diff --git a/node_modules/jest-chain/dist/chain.js b/node_modules/jest-chain/dist/chain.js
index 4a7b85b..cf756ba 100644
--- a/node_modules/jest-chain/dist/chain.js
+++ b/node_modules/jest-chain/dist/chain.js
@@ -17,18 +17,20 @@ class JestAssertionError extends Error {
}
-const chainMatchers = (matchers, originalMatchers = matchers) => {
+const chainMatchers = (matchers, originalMatchers = matchers, value = undefined) => {
const mappedMatchers = Object.keys(matchers).map(name => {
const matcher = matchers[name];
if (typeof matcher === 'function') {
const newMatcher = (...args) => {
try {
- matcher(...args); // run matcher
-
- return chainMatchers(originalMatchers); // chain the original matchers again
+ return chainMatchers(originalMatchers, originalMatchers, matcher(...args)); // chain the original matchers again
} catch (error) {
- throw new JestAssertionError(error.matcherResult, newMatcher);
+ if (error.matcherResult) {
+ throw new JestAssertionError(error.matcherResult, newMatcher);
+ }
+
+ throw error;
}
};
@@ -42,7 +44,7 @@ const chainMatchers = (matchers, originalMatchers = matchers) => {
};
});
- return Object.assign({}, ...mappedMatchers);
+ return Object.assign(Promise.resolve(value), ...mappedMatchers);
};
var _default = expect => {
diff --git a/node_modules/jest-chain/types/index.d.ts b/node_modules/jest-chain/types/index.d.ts
index a952678..4ff766e 100644
--- a/node_modules/jest-chain/types/index.d.ts
+++ b/node_modules/jest-chain/types/index.d.ts
@@ -4,7 +4,7 @@ declare namespace jest {
interface ChainedMatchers<T>
extends jest.JestMatchersShape<
Matchers<ChainedMatchers<T>, T>,
- Matchers<Promise<ChainedMatchers<T>>, T>
+ Matchers<Promise<ChainedMatchers<T>> & ChainedMatchers<T>, T>
> {}
interface Expect {
@RA80533
Copy link
Author

RA80533 commented Nov 12, 2020

Patch for jest-chain which fixes several outstanding issues including Promise support and error propagation

$ git apply -p2 --directory="node_modules" --unsafe-paths "jest-chain+1.1.5.patch"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment