-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure vitest and add test for Header component
- Loading branch information
1 parent
efcf055
commit 161f26c
Showing
7 changed files
with
1,285 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
VITE_FIREBASE_API_KEY= | ||
VITE_FIREBASE_APP_ID= | ||
VITE_FIREBASE_MESSAGING_SENDER_ID= | ||
VITE_FIREBASE_PROJECT_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ node_modules | |
dist | ||
dist-ssr | ||
*.local | ||
coverage | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { describe, it, expect, beforeEach, vi } from 'vitest'; | ||
import { shallowMount } from '@vue/test-utils'; | ||
import Header from './Header.vue'; | ||
import * as logoutService from '../services/logout'; | ||
|
||
|
||
describe('<Header />', () => { | ||
const render = () => shallowMount(Header); | ||
const doLogout = vi.spyOn(logoutService, 'doLogout'); | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks() | ||
}); | ||
|
||
it('should render component correctly', () => { | ||
const wrapper = render(); | ||
const links = wrapper.findAll('router-link'); | ||
|
||
expect(wrapper.exists()).toBeTruthy(); | ||
expect(links.length).toBe(2); | ||
expect(links.at(0)?.text()).toContain('Links4Later'); | ||
expect(links.at(1)?.text()).toContain('Sign out'); | ||
}); | ||
|
||
it('should do logout when sign out buttons is clicked', () => { | ||
const wrapper = render(); | ||
const signOutButton = wrapper.findAll('router-link').at(1); | ||
|
||
signOutButton?.trigger('click') | ||
|
||
expect(doLogout).toHaveBeenCalledTimes(1); | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/// <reference types="vitest" /> | ||
|
||
import { defineConfig } from 'vite' | ||
import Vue from '@vitejs/plugin-vue' | ||
|
||
export default defineConfig({ | ||
plugins: [ | ||
Vue(), | ||
], | ||
test: { | ||
globals: false, | ||
watch: false, | ||
environment: 'jsdom', | ||
coverage: { | ||
provider: 'istanbul', // or 'v8' | ||
reporter: ['clover', 'html'], | ||
}, | ||
}, | ||
}) |
Oops, something went wrong.