diff options
author | Florian Dold <florian@dold.me> | 2021-10-11 10:58:55 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-10-11 10:58:55 +0200 |
commit | f23a8ee4d356645ae3f91862552b256f230c6bcb (patch) | |
tree | 641bf808ef6c6bf7eb003d96f6f7ed5654f854b8 /packages/anastasis-webui/tests | |
parent | 0bbaafcd36ce68f95faee0b91738a169848c7a90 (diff) | |
download | wallet-core-f23a8ee4d356645ae3f91862552b256f230c6bcb.tar.xz |
anastasis-webui: first commit
Diffstat (limited to 'packages/anastasis-webui/tests')
5 files changed, 45 insertions, 0 deletions
diff --git a/packages/anastasis-webui/tests/__mocks__/browserMocks.ts b/packages/anastasis-webui/tests/__mocks__/browserMocks.ts new file mode 100644 index 000000000..5be8c3ce6 --- /dev/null +++ b/packages/anastasis-webui/tests/__mocks__/browserMocks.ts @@ -0,0 +1,21 @@ +// Mock Browser API's which are not supported by JSDOM, e.g. ServiceWorker, LocalStorage +/** + * An example how to mock localStorage is given below 👇 + */ + +/* +// Mocks localStorage +const localStorageMock = (function() { + let store = {}; + + return { + getItem: (key) => store[key] || null, + setItem: (key, value) => store[key] = value.toString(), + clear: () => store = {} + }; + +})(); + +Object.defineProperty(window, 'localStorage', { + value: localStorageMock +}); */ diff --git a/packages/anastasis-webui/tests/__mocks__/fileMocks.ts b/packages/anastasis-webui/tests/__mocks__/fileMocks.ts new file mode 100644 index 000000000..87109e355 --- /dev/null +++ b/packages/anastasis-webui/tests/__mocks__/fileMocks.ts @@ -0,0 +1,3 @@ +// This fixed an error related to the CSS and loading gif breaking my Jest test +// See https://facebook.github.io/jest/docs/en/webpack.html#handling-static-assets +export default 'test-file-stub'; diff --git a/packages/anastasis-webui/tests/__mocks__/setupTests.ts b/packages/anastasis-webui/tests/__mocks__/setupTests.ts new file mode 100644 index 000000000..01dc92a29 --- /dev/null +++ b/packages/anastasis-webui/tests/__mocks__/setupTests.ts @@ -0,0 +1,6 @@ +import { configure } from 'enzyme'; +import Adapter from 'enzyme-adapter-preact-pure'; + +configure({ + adapter: new Adapter() +}); diff --git a/packages/anastasis-webui/tests/declarations.d.ts b/packages/anastasis-webui/tests/declarations.d.ts new file mode 100644 index 000000000..67e940277 --- /dev/null +++ b/packages/anastasis-webui/tests/declarations.d.ts @@ -0,0 +1,3 @@ +// Enable enzyme adapter's integration with TypeScript +// See: https://github.com/preactjs/enzyme-adapter-preact-pure#usage-with-typescript +/// <reference types="enzyme-adapter-preact-pure" /> diff --git a/packages/anastasis-webui/tests/header.test.tsx b/packages/anastasis-webui/tests/header.test.tsx new file mode 100644 index 000000000..b2cfc2f4d --- /dev/null +++ b/packages/anastasis-webui/tests/header.test.tsx @@ -0,0 +1,12 @@ +import { h } from 'preact'; +import Header from '../src/components/header'; +// See: https://github.com/preactjs/enzyme-adapter-preact-pure +import { shallow } from 'enzyme'; + +describe('Initial Test of the Header', () => { + test('Header renders 3 nav items', () => { + const context = shallow(<Header />); + expect(context.find('h1').text()).toBe('Preact App'); + expect(context.find('Link').length).toBe(3); + }); +}); |