mirror of
https://github.com/prymitive/karma
synced 2026-09-04 11:27:19 +00:00
refactor(tests): use jest-mock-console for mocking console calls
This commit is contained in:
Generated
+6
@@ -6482,6 +6482,12 @@
|
||||
"resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-20.0.3.tgz",
|
||||
"integrity": "sha1-i8Bw6QQUqhVcEajWTIaaDVxx2lk="
|
||||
},
|
||||
"jest-mock-console": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/jest-mock-console/-/jest-mock-console-0.4.0.tgz",
|
||||
"integrity": "sha512-WElCbNvfqQlD7cpfHfTn1ytZ+RjKg1Ftrvr5wEjdWP7a9esXmaiZuEAPeYUSK5fd0Cra+dR1oF8HAjjKKxDQdg==",
|
||||
"dev": true
|
||||
},
|
||||
"jest-regex-util": {
|
||||
"version": "20.0.3",
|
||||
"resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-20.0.3.tgz",
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
"eslint-plugin-react": "7.11.1",
|
||||
"jest-fetch-mock": "1.6.5",
|
||||
"jest-localstorage-mock": "2.2.0",
|
||||
"jest-mock-console": "0.4.0",
|
||||
"markdownlint-cli": "0.13.0",
|
||||
"node-sass-chokidar": "1.3.3",
|
||||
"onchange": "4.1.0",
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { ConsoleMock } from "__mocks__/Console";
|
||||
import { EmptyAPIResponse } from "__mocks__/Fetch";
|
||||
|
||||
import {
|
||||
@@ -192,7 +191,7 @@ describe("DecodeLocationSearch", () => {
|
||||
|
||||
describe("AlertStore.fetch", () => {
|
||||
it("parseAPIResponse() rejects a response with mismatched filters", () => {
|
||||
const consoleSpy = ConsoleMock("info");
|
||||
const consoleSpy = jest.spyOn(console, "info");
|
||||
|
||||
const response = EmptyAPIResponse();
|
||||
const store = new AlertStore([]);
|
||||
@@ -202,7 +201,7 @@ describe("AlertStore.fetch", () => {
|
||||
// there should be no filters set on AlertStore instance since we started
|
||||
// with 0 and rejected response with 1 filter
|
||||
expect(store.filters.values).toHaveLength(0);
|
||||
// console.info should have been called since we emited a warning
|
||||
// console.info should have been called since we emited a log line
|
||||
expect(consoleSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
consoleSpy.mockRestore();
|
||||
@@ -242,7 +241,7 @@ describe("AlertStore.fetch", () => {
|
||||
});
|
||||
|
||||
it("fetch() handles response that throws an error correctly", async () => {
|
||||
const consoleSpy = ConsoleMock("trace");
|
||||
const consoleSpy = jest.spyOn(console, "trace");
|
||||
fetch.mockReject("Fetch error");
|
||||
|
||||
const store = new AlertStore([]);
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
const ConsoleMock = level =>
|
||||
jest.spyOn(console, level).mockImplementation(() => jest.fn());
|
||||
|
||||
export { ConsoleMock };
|
||||
@@ -1,3 +1,8 @@
|
||||
import mockConsole from "jest-mock-console";
|
||||
|
||||
// mock console
|
||||
mockConsole(["error", "warn", "info", "log", "trace"]);
|
||||
|
||||
// localStorage is used for Settings store
|
||||
require("jest-localstorage-mock");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user