Fail on console errors when testing enzyme (#769)

`testUtil.configureEnzyme` now additionally asserts, after every test,
that `console.error` and `console.warn` were not called. Tests that
explicitly expect such calls can still be written by manually re-mocking
the relevant console method (and several examples already exist).

The code that explicitly specifies this for various enzyme test files
has been removed.

Test plan: `git grep "not.toHaveBeenCalled"` shows only unrelated usage.
`yarn test` passes. Adding a spurious console.warn to a passing test
causes it to fail.

Fixes #668
This commit is contained in:
Dandelion Mané 2018-09-05 11:12:38 -07:00 committed by GitHub
parent d2727c01ba
commit f191995c61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 10 additions and 60 deletions

View File

@ -12,17 +12,6 @@ import createRelativeHistory from "./createRelativeHistory";
require("./testUtil").configureEnzyme();
describe("app/createRelativeHistory", () => {
beforeEach(() => {
// $ExpectFlowError
console.error = jest.fn();
// $ExpectFlowError
console.warn = jest.fn();
});
afterEach(() => {
expect(console.warn).not.toHaveBeenCalled();
expect(console.error).not.toHaveBeenCalled();
});
function createHistory(basename, path) {
const memoryHistory = createMemoryHistory(path);
const relativeHistory = createRelativeHistory(memoryHistory, basename);

View File

@ -22,14 +22,6 @@ require("../testUtil").configureAphrodite();
describe("app/credExplorer/RepositorySelect", () => {
beforeEach(() => {
fetch.resetMocks();
// $ExpectFlowError
console.error = jest.fn();
// $ExpectFlowError
console.warn = jest.fn();
});
afterEach(() => {
expect(console.warn).not.toHaveBeenCalled();
expect(console.error).not.toHaveBeenCalled();
});
function mockRegistry(registry: RepoRegistry) {

View File

@ -21,16 +21,6 @@ import {factorioNodes} from "../../adapters/demoAdapters";
require("../../testUtil").configureEnzyme();
describe("app/credExplorer/pagerankTable/Aggregation", () => {
beforeEach(() => {
// $ExpectFlowError
console.error = jest.fn();
// $ExpectFlowError
console.warn = jest.fn();
});
afterEach(() => {
expect(console.warn).not.toHaveBeenCalled();
expect(console.error).not.toHaveBeenCalled();
});
describe("AggregationRowList", () => {
it("instantiates AggregationRows for each aggregation", async () => {
const {adapters, pnd} = await example();

View File

@ -14,17 +14,6 @@ import {factorioNodes} from "../../adapters/demoAdapters";
require("../../testUtil").configureEnzyme();
describe("app/credExplorer/pagerankTable/Connection", () => {
beforeEach(() => {
// $ExpectFlowError
console.error = jest.fn();
// $ExpectFlowError
console.warn = jest.fn();
});
afterEach(() => {
expect(console.warn).not.toHaveBeenCalled();
expect(console.error).not.toHaveBeenCalled();
});
describe("ConnectionRowList", () => {
async function setup(maxEntriesPerList: number = 100000) {
const {adapters, pnd} = await example();

View File

@ -17,16 +17,6 @@ import {factorioNodes} from "../../adapters/demoAdapters";
require("../../testUtil").configureEnzyme();
describe("app/credExplorer/pagerankTable/Node", () => {
beforeEach(() => {
// $ExpectFlowError
console.error = jest.fn();
// $ExpectFlowError
console.warn = jest.fn();
});
afterEach(() => {
expect(console.warn).not.toHaveBeenCalled();
expect(console.error).not.toHaveBeenCalled();
});
describe("NodeRowList", () => {
function sortedByScore(nodes: $ReadOnlyArray<NodeAddressT>, pnd) {
return sortBy(nodes, (node) => -NullUtil.get(pnd.get(node)).score);

View File

@ -10,16 +10,6 @@ import {example, COLUMNS} from "./sharedTestUtils";
require("../../testUtil").configureEnzyme();
describe("app/credExplorer/pagerankTable/Table", () => {
beforeEach(() => {
// $ExpectFlowError
console.error = jest.fn();
// $ExpectFlowError
console.warn = jest.fn();
});
afterEach(() => {
expect(console.warn).not.toHaveBeenCalled();
expect(console.error).not.toHaveBeenCalled();
});
describe("PagerankTable", () => {
it("renders thead column order properly", async () => {
const {pnd, adapters} = await example();

View File

@ -4,6 +4,16 @@ export function configureEnzyme() {
const Enzyme = require("enzyme");
const Adapter = require("enzyme-adapter-react-16");
Enzyme.configure({adapter: new Adapter()});
beforeEach(() => {
// $ExpectFlowError
console.error = jest.fn();
// $ExpectFlowError
console.warn = jest.fn();
});
afterEach(() => {
expect(console.warn).not.toHaveBeenCalled();
expect(console.error).not.toHaveBeenCalled();
});
}
export function configureAphrodite() {