Skip to content

Commit

Permalink
fix(expect): add types test and improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Oct 11, 2021
1 parent 3a85065 commit 3b3c47c
Show file tree
Hide file tree
Showing 5 changed files with 577 additions and 185 deletions.
1 change: 1 addition & 0 deletions packages/expect/src/__tests__/assertionCounts.test.ts
Expand Up @@ -37,6 +37,7 @@ describe('.hasAssertions()', () => {

it('throws if expected is not undefined', () => {
jestExpect(() => {
// @ts-expect-error
jestExpect.hasAssertions(2);
}).toThrowErrorMatchingSnapshot();
});
Expand Down
15 changes: 6 additions & 9 deletions packages/expect/src/jestMatchersObject.ts
Expand Up @@ -98,15 +98,12 @@ export const setMatchers = <State extends MatcherState = MatcherState>(
}
}

expect[key] = (...sample: [unknown, ...Array<unknown>]) =>
new CustomMatcher(false, ...sample);
if (!expect.not) {
throw new Error(
'`expect.not` is not defined - please report this bug to https://github.com/facebook/jest',
);
}
expect.not[key] = (...sample: [unknown, ...Array<unknown>]) =>
new CustomMatcher(true, ...sample);
Object.defineProperty(expect, key, {
value: (...sample: Array<unknown>) => new CustomMatcher(false, sample),
});
Object.defineProperty(expect.not, key, {
value: (...sample: Array<unknown>) => new CustomMatcher(true, sample),
});
}
});

Expand Down

0 comments on commit 3b3c47c

Please sign in to comment.