Skip to content

Commit

Permalink
jest-circus failure messages
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronabramov committed Jun 9, 2017
1 parent f238a43 commit 1dbfa55
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 27 deletions.
21 changes: 0 additions & 21 deletions integration_tests/__tests__/__snapshots__/failures-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,30 @@ exports[`not throwing Error objects 3`] = `
exports[`not throwing Error objects 4`] = `
" FAIL __tests__/assertion-count-test.js
● .assertions() › throws
expect(received).toBeTruthy()
Expected value to be truthy, instead received
false
at __tests__/assertion-count-test.js:14:17
● .assertions() › throws
expect.assertions(2)
Expected two assertions to be called but only received one assertion call.
● .assertions() › throws on redeclare of assertion count
expect(received).toBeTruthy()
Expected value to be truthy, instead received
false
at __tests__/assertion-count-test.js:18:17
● .assertions() › throws on assertion
expect.assertions(0)
Expected zero assertions to be called but only received one assertion call.
● .hasAssertions() › throws when there are not assertions
expect.hasAssertions()
Expected at least one assertion to be called but received none.
.assertions()
✕ throws
✕ throws on redeclare of assertion count
✕ throws on assertion
.hasAssertions()
✕ throws when there are not assertions
"
`;

Expand Down
7 changes: 5 additions & 2 deletions integration_tests/__tests__/failures-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const normalizeDots = text => text.replace(/\.{1,}$/gm, '.');
skipOnWindows.suite();

const cleanupStackTrace = stderr => {
const STACK_REGEXP = /at.*(setup-jest-globals|extractExpectedAssertionsErrors).*\n/gm;
const STACK_REGEXP = /^.*at.*(setup-jest-globals|extractExpectedAssertionsErrors).*\n/gm;
if (!STACK_REGEXP.test(stderr)) {
throw new Error(
`
Expand All @@ -33,7 +33,10 @@ const cleanupStackTrace = stderr => {
);
}

return stderr.replace(STACK_REGEXP, '');
return stderr
.replace(STACK_REGEXP, '')
// Also remove trailing whitespace.
.replace(/\s+$/gm, '');
};

test('not throwing Error objects', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import type {TestResult, Status} from 'types/TestResult';
import type {GlobalConfig, Path, ProjectConfig} from 'types/Config';
import type {Event, TestEntry} from '../../types';

import {extractExpectedAssertionsErrors, getState, setState} from 'jest-matchers';
import {
extractExpectedAssertionsErrors,
getState,
setState,
} from 'jest-matchers';
import {formatResultsErrors} from 'jest-message-util';
import {SnapshotState, addSerializer} from 'jest-snapshot';
import {addEventHandler, ROOT_DESCRIBE_BLOCK_NAME} from '../state';
Expand Down
6 changes: 3 additions & 3 deletions packages/jest-matchers/src/extractExpectedAssertionsErrors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
* @flow
*/

const {
import {
EXPECTED_COLOR,
RECEIVED_COLOR,
matcherHint,
pluralize,
} = require('jest-matcher-utils');
} from 'jest-matcher-utils';

const {getState, setState} = require('./jest-matchers-object');
import {getState, setState} from './jest-matchers-object';

// Create and format all errors related to the mismatched number of `expect`
// calls and reset the matchers state.
Expand Down

0 comments on commit 1dbfa55

Please sign in to comment.