8620532a05
This contains also multiple fixes to make it work. The following is a non-exhaustive list. When @Prop default value is a callback, then it is called instead of set verbatim. This means, when you want a default value to be a callback, then it needs to be `default: () => () => X`. jest does not yet properly support WebWorkers, hence the code introduces an indirection to provide the worker URL. This in turn required removing the global "store" dependency from the tests. As a consequence the new NotificatorPlugin takes store as a dependency. And many of the tests are adjusted to not import store directly. Moved StoreModule definition to avoid initializing the global store. Some of the router code was moved into store. We can later figure out how to structure it better and move it back. bip39 needs explicit fallbacks for some of the dependencies. Fixes to timer mocking. jest supports it natively. Remove sinon dependency. jest provides all the functionality we need. Change-Id: I7af3599390c63ce9f99dbd0b1e0870e9f8ca994d
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
import PagesBlock from '@/components/common/PagesBlock.vue';
|
|
|
|
import { Page } from '@/types/pagination';
|
|
import { shallowMount } from '@vue/test-utils';
|
|
|
|
describe('Pagination.vue', () => {
|
|
it('renders correctly without props', () => {
|
|
const wrapper = shallowMount(PagesBlock);
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
});
|
|
|
|
it('renders correctly with props', () => {
|
|
const callbackSpy = jest.fn();
|
|
const pagesArray: Page[] = [];
|
|
const SELECTED_PAGE_INDEX = 3;
|
|
|
|
for (let i = 1; i <= 4; i++) {
|
|
pagesArray.push(new Page(i, callbackSpy));
|
|
}
|
|
|
|
const wrapper = shallowMount(PagesBlock, {
|
|
propsData: {
|
|
pages: pagesArray,
|
|
isSelected: (i: number) => i === SELECTED_PAGE_INDEX,
|
|
},
|
|
});
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
expect(wrapper.findAll('span').length).toBe(4);
|
|
expect(wrapper.findAll('span').at(2).classes().includes('selected')).toBe(true);
|
|
});
|
|
|
|
it('behaves correctly on page click', () => {
|
|
const callbackSpy = jest.fn();
|
|
const pagesArray: Page[] = [];
|
|
|
|
for (let i = 1; i <= 3; i++) {
|
|
pagesArray.push(new Page(i, callbackSpy));
|
|
}
|
|
|
|
const wrapper = shallowMount(PagesBlock, {
|
|
propsData: {
|
|
pages: pagesArray,
|
|
isSelected: () => false,
|
|
},
|
|
});
|
|
|
|
wrapper.findAll('span').at(1).trigger('click');
|
|
|
|
expect(callbackSpy).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|