mirror of
https://github.com/dec0dOS/zero-ui.git
synced 2025-07-16 10:03:12 -07:00
test(Bar): add snapshot tests
This commit is contained in:
parent
8cf996eed6
commit
ff96b43758
4 changed files with 154 additions and 1 deletions
47
frontend/__tests__/unit/components/Bar.test.jsx
Normal file
47
frontend/__tests__/unit/components/Bar.test.jsx
Normal file
|
@ -0,0 +1,47 @@
|
|||
import { render } from "@testing-library/react";
|
||||
import Bar from "components/Bar";
|
||||
import { Router } from "react-router-dom";
|
||||
import { createMemoryHistory } from "history";
|
||||
|
||||
// Useful reference: https://bholmes.dev/blog/mocking-browser-apis-fetch-localstorage-dates-the-easy-way-with-jest/
|
||||
|
||||
let mockStorage = {};
|
||||
|
||||
describe("Bar", () => {
|
||||
beforeAll(() => {
|
||||
global.Storage.prototype.getItem = jest.fn((key) => mockStorage[key]);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
// make sure the fridge starts out empty for each test
|
||||
mockStorage = {};
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
global.Storage.prototype.getItem.mockReset();
|
||||
});
|
||||
|
||||
it("renders Bar unchanged when logged out", () => {
|
||||
const history = createMemoryHistory();
|
||||
mockStorage["loggedIn"] = false;
|
||||
|
||||
const { container } = render(
|
||||
<Router history={history}>
|
||||
<Bar />
|
||||
</Router>
|
||||
);
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("renders Bar unchanged when logged in", () => {
|
||||
const history = createMemoryHistory();
|
||||
mockStorage["loggedIn"] = true;
|
||||
|
||||
const { container } = render(
|
||||
<Router history={history}>
|
||||
<Bar />
|
||||
</Router>
|
||||
);
|
||||
expect(container).toMatchSnapshot();
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue