Test config (#122)

* Automatically reset / clear mocks between tests

* Fix test for private view

* Fix tooltip test

* Fix router tests

* Fix all other tests
This commit is contained in:
Rijk van Zanten
2020-02-27 10:31:47 -05:00
committed by GitHub
parent 47649d29a4
commit ad459aa53a
7 changed files with 46 additions and 41 deletions

View File

@@ -2,60 +2,65 @@ import { shallowMount, createLocalVue, Wrapper } from '@vue/test-utils';
import VueCompositionAPI from '@vue/composition-api';
import PrivateView from './private-view.vue';
import VOverlay from '@/components/v-overlay';
import useWindowSize from '@/compositions/window-size';
let mockWidth = 50;
jest.mock('@/compositions/window-size', () =>
jest.fn().mockImplementation(() => {
return {
width: {
value: mockWidth
},
height: {
value: mockWidth
}
};
})
);
import * as windowSize from '@/compositions/window-size';
const localVue = createLocalVue();
localVue.use(VueCompositionAPI);
localVue.component('v-overlay', VOverlay);
describe('Views / Private', () => {
beforeEach(() => {
(useWindowSize as jest.Mock).mockClear();
});
it('Shows nav with overlay if screen is < 960px', async () => {
mockWidth = 600;
jest.spyOn(windowSize, 'default').mockImplementation(() => ({
width: { value: 600 },
height: { value: 600 }
}));
const component = shallowMount(PrivateView, { localVue });
expect((component.vm as any).navWithOverlay).toBe(true);
});
it('Does not render overlay for nav if screen is >= 960px', async () => {
mockWidth = 960;
jest.spyOn(windowSize, 'default').mockImplementation(() => ({
width: { value: 960 },
height: { value: 960 }
}));
let component = shallowMount(PrivateView, { localVue });
expect((component.vm as any).navWithOverlay).toBe(false);
mockWidth = 1000;
(windowSize.default as jest.Mock).mockImplementation(() => ({
width: { value: 1000 },
height: { value: 1000 }
}));
component = shallowMount(PrivateView, { localVue });
expect((component.vm as any).navWithOverlay).toBe(false);
});
it('Shows drawer with overlay if screen is < 1260px', async () => {
mockWidth = 600;
jest.spyOn(windowSize, 'default').mockImplementation(() => ({
width: { value: 600 },
height: { value: 600 }
}));
const component = shallowMount(PrivateView, { localVue });
expect((component.vm as any).drawerWithOverlay).toBe(true);
});
it('Does not render overlay for drawer if screen is >= 1260px', async () => {
mockWidth = 1260;
jest.spyOn(windowSize, 'default').mockImplementation(() => ({
width: { value: 1260 },
height: { value: 1260 }
}));
let component = shallowMount(PrivateView, { localVue });
expect((component.vm as any).drawerWithOverlay).toBe(false);
mockWidth = 1300;
(windowSize.default as jest.Mock).mockImplementation(() => ({
width: { value: 1300 },
height: { value: 1300 }
}));
component = shallowMount(PrivateView, { localVue });
expect((component.vm as any).drawerWithOverlay).toBe(false);
});