mirror of
https://github.com/prymitive/karma
synced 2026-05-15 04:06:41 +00:00
fix(tests): reset mocks between tests
Ensures that tests don't rely on previous tests mocking things
This commit is contained in:
@@ -12,6 +12,7 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
window.history.pushState({}, "App", "/");
|
||||
});
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ beforeAll(() => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
// reset sentry state before each mock, that's the only way to revert
|
||||
// Sentry.init() that I found
|
||||
global.__SENTRY__ = {};
|
||||
|
||||
@@ -11,6 +11,10 @@ beforeEach(() => {
|
||||
alertStore = new AlertStore([]);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
const MountedFaviconBadge = () => {
|
||||
return mount(<FaviconBadge alertStore={alertStore} />);
|
||||
};
|
||||
|
||||
@@ -34,6 +34,7 @@ beforeEach(() => {
|
||||
afterEach(() => {
|
||||
jest.clearAllTimers();
|
||||
jest.clearAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
clear();
|
||||
});
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
// reset Date() to current time
|
||||
clear();
|
||||
});
|
||||
|
||||
@@ -18,6 +18,10 @@ beforeEach(() => {
|
||||
silenceFormStore = new SilenceFormStore();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
const ShallowAlertGrid = () => {
|
||||
return shallow(
|
||||
<AlertGrid
|
||||
|
||||
@@ -13,6 +13,7 @@ beforeEach(() => {
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllTimers();
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe("<UpgradeNeeded />", () => {
|
||||
|
||||
@@ -18,6 +18,10 @@ beforeEach(() => {
|
||||
onHide.mockClear();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
const FakeModal = () => {
|
||||
return mount(
|
||||
<MainModalContent
|
||||
|
||||
@@ -18,6 +18,10 @@ beforeEach(() => {
|
||||
fetch.resetMocks();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
const MountedInput = () => {
|
||||
return mount(
|
||||
<FilterInput alertStore={alertStore} settingsStore={settingsStore} />
|
||||
|
||||
@@ -26,6 +26,10 @@ beforeEach(() => {
|
||||
];
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
const ShallowLabelNameInput = isValid => {
|
||||
return shallow(<LabelNameInput matcher={matcher} isValid={isValid} />);
|
||||
};
|
||||
|
||||
@@ -8,12 +8,16 @@ import * as Sentry from "@sentry/browser";
|
||||
|
||||
import { ErrorBoundary } from "./ErrorBoundary";
|
||||
|
||||
let consoleSpy;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.useFakeTimers();
|
||||
consoleSpy = jest.spyOn(console, "error").mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllTimers();
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
const FailingComponent = () => {
|
||||
@@ -30,9 +34,6 @@ const MountedFailingComponent = () => {
|
||||
|
||||
describe("<ErrorBoundary />", () => {
|
||||
it("matches snapshot", () => {
|
||||
const consoleSpy = jest
|
||||
.spyOn(console, "error")
|
||||
.mockImplementation(() => {});
|
||||
const tree = MountedFailingComponent();
|
||||
expect(toDiffableHtml(tree.html())).toMatchSnapshot();
|
||||
expect(consoleSpy).toHaveBeenCalled();
|
||||
@@ -65,9 +66,6 @@ describe("<ErrorBoundary />", () => {
|
||||
});
|
||||
|
||||
it("calls window.location.reload after 60s", () => {
|
||||
const consoleSpy = jest
|
||||
.spyOn(console, "error")
|
||||
.mockImplementation(() => {});
|
||||
const reloadSpy = jest.spyOn(global.window.location, "reload");
|
||||
MountedFailingComponent();
|
||||
jest.runTimersToTime(1000 * 61);
|
||||
@@ -76,7 +74,6 @@ describe("<ErrorBoundary />", () => {
|
||||
});
|
||||
|
||||
it("reloadSeconds is 40 after 20s with multiple exceptions", () => {
|
||||
jest.spyOn(console, "error").mockImplementation(() => {});
|
||||
const tree = MountedFailingComponent();
|
||||
const instance = tree.instance();
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ beforeEach(() => {
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
// wipe REACT_APP_BACKEND_URI env on each run as it's used by some tests
|
||||
delete process.env.REACT_APP_BACKEND_URI;
|
||||
});
|
||||
@@ -279,6 +280,7 @@ describe("AlertStore.fetch", () => {
|
||||
});
|
||||
|
||||
it("unapplied filters are marked as applied on fetch error", async () => {
|
||||
jest.spyOn(console, "trace").mockImplementation(() => {});
|
||||
fetch.mockReject("Fetch error");
|
||||
const store = new AlertStore([NewUnappliedFilter("foo")]);
|
||||
store.filters.values[0].applied = false;
|
||||
|
||||
Reference in New Issue
Block a user