mirror of
https://github.com/prymitive/karma
synced 2026-05-19 04:26:41 +00:00
fix(tests): new jsdom mocks localStorage, no need to provide a mock
This also needs to be mocked a little different: https://github.com/facebook/jest/issues/6798#issuecomment-412871616
This commit is contained in:
@@ -57,7 +57,6 @@
|
||||
"jest-canvas-mock": "1.1.0",
|
||||
"jest-date-mock": "1.0.5",
|
||||
"jest-fetch-mock": "1.6.6",
|
||||
"jest-localstorage-mock": "2.2.0",
|
||||
"markdownlint-cli": "0.13.0",
|
||||
"node-sass": "4.9.3"
|
||||
},
|
||||
|
||||
@@ -36,10 +36,13 @@ describe("<App />", () => {
|
||||
})
|
||||
);
|
||||
|
||||
// https://github.com/facebook/jest/issues/6798#issuecomment-412871616
|
||||
const getItemSpy = jest.spyOn(Storage.prototype, "getItem");
|
||||
|
||||
const tree = shallow(<App defaultFilters={["ignore=defaults"]} />);
|
||||
const instance = tree.instance();
|
||||
|
||||
expect(localStorage.getItem).toHaveBeenCalledWith("savedFilters");
|
||||
expect(getItemSpy).toHaveBeenCalledWith("savedFilters");
|
||||
|
||||
expect(instance.alertStore.filters.values).toHaveLength(2);
|
||||
expect(instance.alertStore.filters.values[0]).toMatchObject(
|
||||
@@ -48,9 +51,11 @@ describe("<App />", () => {
|
||||
expect(instance.alertStore.filters.values[1]).toMatchObject(
|
||||
NewUnappliedFilter("abc!=cba")
|
||||
);
|
||||
|
||||
getItemSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("ignores saved filters if 'preset' key is falsey (use passed defaults)", () => {
|
||||
it("ignores saved filters if 'present' key is falsey (use passed defaults)", () => {
|
||||
expect(window.location.search).toBe("");
|
||||
localStorage.setItem(
|
||||
"savedFilters",
|
||||
@@ -60,15 +65,20 @@ describe("<App />", () => {
|
||||
})
|
||||
);
|
||||
|
||||
// https://github.com/facebook/jest/issues/6798#issuecomment-412871616
|
||||
const getItemSpy = jest.spyOn(Storage.prototype, "getItem");
|
||||
|
||||
const tree = shallow(<App defaultFilters={["use=defaults"]} />);
|
||||
const instance = tree.instance();
|
||||
|
||||
expect(localStorage.getItem).toHaveBeenCalledWith("savedFilters");
|
||||
expect(getItemSpy).toHaveBeenCalledWith("savedFilters");
|
||||
|
||||
expect(instance.alertStore.filters.values).toHaveLength(1);
|
||||
expect(instance.alertStore.filters.values[0]).toMatchObject(
|
||||
NewUnappliedFilter("use=defaults")
|
||||
);
|
||||
|
||||
getItemSpy.mockRestore();
|
||||
});
|
||||
|
||||
it("uses filters passed via ?q= query args (ignoring saved filters and passed defaults)", () => {
|
||||
|
||||
@@ -4,9 +4,6 @@ import Adapter from "enzyme-adapter-react-16";
|
||||
// https://github.com/airbnb/enzyme
|
||||
Enzyme.configure({ adapter: new Adapter() });
|
||||
|
||||
// localStorage is used for Settings store
|
||||
import("jest-localstorage-mock");
|
||||
|
||||
// favico.js needs canvas
|
||||
import("jest-canvas-mock");
|
||||
|
||||
|
||||
@@ -6071,11 +6071,6 @@ jest-leak-detector@^23.6.0:
|
||||
dependencies:
|
||||
pretty-format "^23.6.0"
|
||||
|
||||
jest-localstorage-mock@2.2.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/jest-localstorage-mock/-/jest-localstorage-mock-2.2.0.tgz#ce9a9de01dfdde2ad8aa08adf73acc7e5cc394cf"
|
||||
integrity sha512-x+P0vcwr4540bCAYzTEpiD9rs+zh/QZzyiABV+MU6yM2OPwPlrrLyUx/6gValMyt6tg5lX6Z53o2rHWfUht5Xw==
|
||||
|
||||
jest-matcher-utils@^23.6.0:
|
||||
version "23.6.0"
|
||||
resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-23.6.0.tgz#726bcea0c5294261a7417afb6da3186b4b8cac80"
|
||||
|
||||
Reference in New Issue
Block a user