fix: 修复 Login 组件测试的 Pinia 初始化问题
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
|
||||||
import { mount } from '@vue/test-utils'
|
import { mount } from '@vue/test-utils'
|
||||||
import { createRouter, createMemoryHistory } from 'vue-router'
|
import { createRouter, createMemoryHistory } from 'vue-router'
|
||||||
|
import { createPinia, setActivePinia } from 'pinia'
|
||||||
import Login from '@/views/system/Login.vue'
|
import Login from '@/views/system/Login.vue'
|
||||||
|
|
||||||
vi.mock('vue-router')
|
vi.mock('vue-router')
|
||||||
@@ -20,8 +21,12 @@ vi.mock('@/utils/request', () => ({
|
|||||||
describe('Login Component', () => {
|
describe('Login Component', () => {
|
||||||
let router: any
|
let router: any
|
||||||
let wrapper: any
|
let wrapper: any
|
||||||
|
let pinia: any
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
pinia = createPinia()
|
||||||
|
setActivePinia(pinia)
|
||||||
|
|
||||||
router = createRouter({
|
router = createRouter({
|
||||||
history: createMemoryHistory(),
|
history: createMemoryHistory(),
|
||||||
routes: [
|
routes: [
|
||||||
@@ -44,7 +49,7 @@ describe('Login Component', () => {
|
|||||||
it('should render login form', () => {
|
it('should render login form', () => {
|
||||||
wrapper = mount(Login, {
|
wrapper = mount(Login, {
|
||||||
global: {
|
global: {
|
||||||
plugins: [router],
|
plugins: [router, pinia],
|
||||||
stubs: {
|
stubs: {
|
||||||
'el-card': true,
|
'el-card': true,
|
||||||
'el-form': true,
|
'el-form': true,
|
||||||
@@ -62,7 +67,7 @@ describe('Login Component', () => {
|
|||||||
it('should initialize with empty form state', () => {
|
it('should initialize with empty form state', () => {
|
||||||
wrapper = mount(Login, {
|
wrapper = mount(Login, {
|
||||||
global: {
|
global: {
|
||||||
plugins: [router],
|
plugins: [router, pinia],
|
||||||
stubs: {
|
stubs: {
|
||||||
'el-card': true,
|
'el-card': true,
|
||||||
'el-form': true,
|
'el-form': true,
|
||||||
@@ -80,7 +85,7 @@ describe('Login Component', () => {
|
|||||||
it('should initialize loading as false', () => {
|
it('should initialize loading as false', () => {
|
||||||
wrapper = mount(Login, {
|
wrapper = mount(Login, {
|
||||||
global: {
|
global: {
|
||||||
plugins: [router],
|
plugins: [router, pinia],
|
||||||
stubs: {
|
stubs: {
|
||||||
'el-card': true,
|
'el-card': true,
|
||||||
'el-form': true,
|
'el-form': true,
|
||||||
@@ -99,7 +104,7 @@ describe('Login Component', () => {
|
|||||||
it('should update username when input changes', async () => {
|
it('should update username when input changes', async () => {
|
||||||
wrapper = mount(Login, {
|
wrapper = mount(Login, {
|
||||||
global: {
|
global: {
|
||||||
plugins: [router],
|
plugins: [router, pinia],
|
||||||
stubs: {
|
stubs: {
|
||||||
'el-card': true,
|
'el-card': true,
|
||||||
'el-form': true,
|
'el-form': true,
|
||||||
@@ -119,7 +124,7 @@ describe('Login Component', () => {
|
|||||||
it('should update password when input changes', async () => {
|
it('should update password when input changes', async () => {
|
||||||
wrapper = mount(Login, {
|
wrapper = mount(Login, {
|
||||||
global: {
|
global: {
|
||||||
plugins: [router],
|
plugins: [router, pinia],
|
||||||
stubs: {
|
stubs: {
|
||||||
'el-card': true,
|
'el-card': true,
|
||||||
'el-form': true,
|
'el-form': true,
|
||||||
@@ -141,7 +146,7 @@ describe('Login Component', () => {
|
|||||||
it('should have onFinish method', () => {
|
it('should have onFinish method', () => {
|
||||||
wrapper = mount(Login, {
|
wrapper = mount(Login, {
|
||||||
global: {
|
global: {
|
||||||
plugins: [router],
|
plugins: [router, pinia],
|
||||||
stubs: {
|
stubs: {
|
||||||
'el-card': true,
|
'el-card': true,
|
||||||
'el-form': true,
|
'el-form': true,
|
||||||
@@ -162,7 +167,7 @@ describe('Login Component', () => {
|
|||||||
|
|
||||||
wrapper = mount(Login, {
|
wrapper = mount(Login, {
|
||||||
global: {
|
global: {
|
||||||
plugins: [router],
|
plugins: [router, pinia],
|
||||||
stubs: {
|
stubs: {
|
||||||
'el-card': true,
|
'el-card': true,
|
||||||
'el-form': true,
|
'el-form': true,
|
||||||
|
|||||||
Reference in New Issue
Block a user