feat: init

This commit is contained in:
ex_zhangwenlei@exiot.cmcc
2024-01-02 21:50:01 +08:00
commit df02b23b2d
69 changed files with 7333 additions and 0 deletions

41
__test__/Button.test.ts Normal file
View File

@@ -0,0 +1,41 @@
import Button from '@/components/Button/index.vue'
import { shallowMount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
// 测试分组
describe('Button', () => {
// mount
test('Buttons slot text', () => {
// @vue/test-utils
const wrapper = shallowMount(Button, {
slots: {
default: 'Button',
},
})
// 断言
expect(wrapper.text()).toBe('Button')
})
test('Button click', () => {
const wrapper = shallowMount(Button)
wrapper.trigger('click')
expect(wrapper.emitted('click')).toBeTruthy()
})
test('Button disabled', () => {
const wrapper = shallowMount(Button, {
props: {
disabled: true,
},
})
wrapper.trigger('click')
expect(wrapper.emitted('click')).toBeFalsy()
})
test('Button not disabled', () => {
const wrapper = shallowMount(Button, {
props: {
disabled: false,
},
})
wrapper.trigger('click')
expect(wrapper.emitted('click')).toBeTruthy()
})
})

31
__test__/Request.test.ts Normal file
View File

@@ -0,0 +1,31 @@
// test axios request
import Request from '@/api/request';
import { describe, it, expect, vi } from 'vitest';
import { mount, flushPromises } from '@vue/test-utils';
import axios from 'axios';
const fn = vi.fn();
const mockRes = {
data: {
code: 200,
success: true,
message: 'success',
data: {
name: 'test',
age: 18,
},
},
};
fn(mockRes);
fn.mock.calls[0] === [mockRes];
describe('Request', () => {
it('should return data when request success', async () => {
const request = new Request();
const res = await request({
url: '/test',
method: 'GET',
});
expect(res).toEqual(mockRes.data);
});
});