fix(ui): fixing tests that stopped working with rca 2.0

This commit is contained in:
Łukasz Mierzwa
2018-10-03 08:47:47 +01:00
parent e3c43453ea
commit 699e2bafa8
5 changed files with 19 additions and 4 deletions

View File

@@ -2,6 +2,14 @@ import * as Sentry from "@sentry/browser";
import { SettingsElement, SetupSentry, ParseDefaultFilters } from "./AppBoot";
beforeAll(() => {
// https://github.com/jamesmfriedman/rmwc/issues/103#issuecomment-360007979
Object.defineProperty(window.HTMLElement.prototype, "dataset", {
writable: true,
value: {}
});
});
afterEach(() => {
// reset sentry state before each mock, that's the only way to revert
// Sentry.init() that I found

View File

@@ -52,6 +52,7 @@ exports[`<Alert /> matches snapshot with showAlertmanagers=false showReceiver=fa
role=\\"img\\"
xmlns=\\"http://www.w3.org/2000/svg\\"
viewbox=\\"0 0 320 512\\"
style=\\"width: 0.8rem;\\"
>
<path fill=\\"currentColor\\"
d=\\"M31.3 192h257.3c17.8 0 26.7 21.5 14.1 34.1L174.1 354.8c-7.8 7.8-20.5 7.8-28.3 0L17.2 226.1C4.6 213.5 13.5 192 31.3 192z\\"

View File

@@ -22,7 +22,9 @@ describe("<UpgradeNeeded />", () => {
});
it("calls window.location.reload after timer is done", () => {
const reloadSpy = jest.spyOn(global.window.location, "reload");
const reloadSpy = jest
.spyOn(global.window.location, "reload")
.mockImplementation(() => {});
mount(<UpgradeNeeded newVersion="1.2.3" />);
jest.runOnlyPendingTimers();
expect(reloadSpy).toBeCalled();

View File

@@ -30,8 +30,12 @@ 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();
});
it("componentDidCatch should catch an error from FailingComponent", () => {

View File

@@ -5,13 +5,13 @@ import Adapter from "enzyme-adapter-react-16";
Enzyme.configure({ adapter: new Adapter() });
// localStorage is used for Settings store
require("jest-localstorage-mock");
import("jest-localstorage-mock");
// favico.js needs canvas
require("jest-canvas-mock");
import("jest-canvas-mock");
// used to mock current time since we render moment.fromNow() in some places
require("jest-date-mock");
import("jest-date-mock");
// fetch is used in multiple places to interact with Go backend
// or upstream Alertmanager API