Skip to content

Commit

Permalink
fix: Reset local state of assertions when using hasAssertions (jestjs…
Browse files Browse the repository at this point in the history
  • Loading branch information
thymikee authored and tabrindle committed Oct 2, 2017
1 parent 3e1131c commit e829f48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/expect/src/__tests__/assertion_counts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ describe('.hasAssertions()', () => {
it('throws if passed parameters', () => {
jestExpect(() => {
jestExpect.hasAssertions(2);
}).toThrow();
}).toThrow(/does not accept any arguments/);
});

it('hasAssertions not leaking to global state', () => {});
});
12 changes: 11 additions & 1 deletion packages/expect/src/extract_expected_assertions_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import {

import {getState, setState} from './jest_matchers_object';

const resetAssertionsLocalState = () => {
setState({
assertionCalls: 0,
expectedAssertionsNumber: null,
isExpectingAssertions: false,
});
};

// Create and format all errors related to the mismatched number of `expect`
// calls and reset the matchers state.
const extractExpectedAssertionsErrors = () => {
Expand All @@ -26,7 +34,9 @@ const extractExpectedAssertionsErrors = () => {
expectedAssertionsNumber,
isExpectingAssertions,
} = getState();
setState({assertionCalls: 0, expectedAssertionsNumber: null});

resetAssertionsLocalState();

if (
typeof expectedAssertionsNumber === 'number' &&
assertionCalls !== expectedAssertionsNumber
Expand Down

0 comments on commit e829f48

Please sign in to comment.