Files
directus/src/hydrate.test.ts
Rijk van Zanten 28531b531b Add hydration, collection store, collections module navigation (#125)
* Add hydration functions and logout route

* Add tests for hydration

* Add collections nav

* Structure collections module, add overview route

* Fix failing tests

* Add test for use-navigation

* Add tests for collections-navigation

* Add tests for collections-overview

* Fix export for use-navigation composition

* Update tests
2020-02-28 16:21:51 -05:00

62 lines
1.6 KiB
TypeScript

import { useCollectionsStore } from './stores/collections/';
import { hydrated, hydrate, dehydrate } from './hydrate';
import Vue from 'vue';
import VueCompositionAPI from '@vue/composition-api';
describe('Hydration', () => {
beforeAll(() => {
Vue.use(VueCompositionAPI);
});
describe('Hydrate', () => {
it('Calls the correct stores', async () => {
const collectionsStore = useCollectionsStore({});
collectionsStore.getCollections = jest.fn();
await hydrate();
expect(collectionsStore.getCollections).toHaveBeenCalled();
});
it('Sets hydrated let after it is done', async () => {
await hydrate();
expect(hydrated).toBe(true);
});
it('Does not hydrate when already hydrated', async () => {
await hydrate();
const collectionsStore = useCollectionsStore({});
collectionsStore.getCollections = jest.fn();
await hydrate();
expect(collectionsStore.getCollections).not.toHaveBeenCalled();
});
});
describe('Dehydrate', () => {
it('Calls resets functions of correct stores', async () => {
const collectionsStore = useCollectionsStore({});
collectionsStore.reset = jest.fn();
await dehydrate();
expect(collectionsStore.reset).toHaveBeenCalled();
});
it('Sets hydrated let after it is done', async () => {
await dehydrate();
expect(hydrated).toBe(false);
});
it('Does not hydrate when already hydrated', async () => {
await dehydrate();
const collectionsStore = useCollectionsStore({});
collectionsStore.reset = jest.fn();
await dehydrate();
expect(collectionsStore.reset).not.toHaveBeenCalled();
});
});
});