Skip to content

Commit

Permalink
fix: resolves #49
Browse files Browse the repository at this point in the history
  • Loading branch information
mnenie committed Sep 2, 2024
1 parent 4493591 commit 6b68046
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/pages/__tests__/NotFound.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import NotFound from '../NotFoundPage.vue';
import { useHead } from '@unhead/vue';
import i18n from '@/shared/lib/i18n';
import { UiButton } from '@/shared/ui';

vi.mock('@unhead/vue', () => ({
useHead: vi.fn()
Expand Down Expand Up @@ -35,7 +36,7 @@ describe('tests for NotFoundPage.vue', () => {
});

it('should redirect correctly', async () => {
await wrapper.findComponent({ name: 'UiButton' }).trigger('click');
await wrapper.findComponent(UiButton).trigger('click');
expect(mockRouter.push).toHaveBeenCalledWith({ name: 'boards' });
});
});
9 changes: 5 additions & 4 deletions src/widgets/layout/ui/header/__tests__/HeaderWelcome.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import HeaderWelcome from '../HeaderWelcome.vue';
import i18n from '@/shared/lib/i18n';
import { Moon, Sun } from 'lucide-vue-next';
import { UiButton, UiSelect } from '@/shared/ui';

const mockRouter = {
push: vi.fn(),
Expand Down Expand Up @@ -40,8 +41,8 @@ describe('tests for HeaderWelcome.vue', () => {
});

it('should render subcomponents', () => {
expect(wrapper.findComponent({ name: 'UiButton' }).exists()).toBe(true);
expect(wrapper.findComponent({ name: 'UiSelect' }).exists()).toBe(true);
expect(wrapper.findComponent(UiButton).exists()).toBe(true);
expect(wrapper.findComponent(UiSelect).exists()).toBe(true);
});

it('should handle mode + icon changing', async () => {
Expand All @@ -61,14 +62,14 @@ describe('tests for HeaderWelcome.vue', () => {
});

it('should redirect correctly to login', async () => {
const loginButton = wrapper.find('.btns').findAllComponents({ name: 'UiButton' }).at(0);
const loginButton = wrapper.find('.btns').findAllComponents(UiButton).at(0);

await loginButton.trigger('click');
expect(mockRouter.push).toHaveBeenCalledWith({ name: 'login' });
});

it('should redirect correctly to registration', async () => {
const registrationButton = wrapper.find('.btns').findAllComponents({ name: 'UiButton' }).at(1);
const registrationButton = wrapper.find('.btns').findAllComponents(UiButton).at(1);

await registrationButton.trigger('click');
expect(mockRouter.push).toHaveBeenCalledWith({ name: 'registration' });
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/layout/ui/header/__tests__/UserMenu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { nextTick } from 'vue';
import '@/shared/lib/vitest-utils/cookiesI18n-mock';
import i18n from '@/shared/lib/i18n';
import UserMenu from '../UserMenu.vue';
import { UiDropdownItem } from '@/shared/ui';
import { UiDropdown, UiDropdownItem } from '@/shared/ui';

const mockRouter = {
push: vi.fn(),
Expand All @@ -30,8 +30,8 @@ describe('tests for UserMenu.vue', () => {
});

it('should be render correctly', async () => {
// TODO(@mnenie): change {name: 'Component'} to Component(instance) for (!all tests) -> name - deprecated
await wrapper.findComponent({ name: 'UiDropdown' }).vm.handleDropdown();
// @ts-expect-error inctance
await wrapper.findComponent(UiDropdown).vm.handleDropdown();
await nextTick();
expect(wrapper.html()).toMatchSnapshot();
});
Expand Down

0 comments on commit 6b68046

Please sign in to comment.