test: is工具及footer组件单元测试

This commit is contained in:
baiqi 2023-06-01 14:14:55 +08:00 committed by rubylliu
parent 33f3e92709
commit 217f9ad0f9
5 changed files with 158 additions and 20 deletions

View File

@ -0,0 +1,28 @@
import { mount } from '@vue/test-utils';
import { describe, expect, test } from 'vitest';
import Footer from '@/components/footer/index.vue';
describe('Footer', () => {
test('renders the correct text', () => {
const wrapper = mount(Footer, {
props: {
text: 'Custom Text',
},
});
expect(wrapper.text()).toBe('Custom Text');
});
test('renders the default text if no prop is provided', () => {
const wrapper = mount(Footer);
expect(wrapper.text()).toBe('MeterSphere');
});
test('applies the correct styles', () => {
const wrapper = mount(Footer);
expect(wrapper.find('.footer').exists()).toBe(true);
expect(wrapper.classes()).toContain('footer');
});
});

View File

@ -0,0 +1,119 @@
import { describe, expect, test } from 'vitest';
import {
isArray,
isObject,
isEmptyObject,
isExist,
isFunction,
isNull,
isUndefined,
isNumber,
isString,
isRegExp,
isFile,
isBlob,
} from '@/utils/is';
import logo from '@/assets/svg/logo.svg';
describe('Is tool', () => {
test('isArray', () => {
const res = isArray([]);
expect(res).toBe(true);
const res2 = isArray('');
expect(res2).toBe(false);
});
test('isObject', () => {
const res = isObject({ a: 'a' });
expect(res).toBe(true);
const res2 = isObject([]);
expect(res2).toBe(false);
});
test('isEmptyObject', () => {
const res = isEmptyObject({});
expect(res).toBe(true);
const res2 = isEmptyObject({ a: 'a' });
expect(res2).toBe(false);
const res3 = isEmptyObject([]);
expect(res3).toBe(false);
});
test('isExist', () => {
const res = isExist(0);
expect(res).toBe(true);
const res2 = isExist(null);
expect(res2).toBe(false);
});
test('isFunction', () => {
const res = isFunction(() => ({}));
expect(res).toBe(true);
const res2 = isFunction({});
expect(res2).toBe(false);
});
test('isNull', () => {
const res = isNull(null);
expect(res).toBe(true);
const res2 = isNull(undefined);
expect(res2).toBe(false);
});
test('isUndefined', () => {
const res = isUndefined(undefined);
expect(res).toBe(true);
const res2 = isUndefined(null);
expect(res2).toBe(false);
});
test('isNumber', () => {
const res = isNumber(0);
expect(res).toBe(true);
const res2 = isNumber(null);
expect(res2).toBe(false);
});
test('isString', () => {
const res = isString('');
expect(res).toBe(true);
const res2 = isString(0);
expect(res2).toBe(false);
});
test('isRegExp', () => {
const res = isRegExp(/^a/);
expect(res).toBe(true);
const res2 = isRegExp('');
expect(res2).toBe(false);
});
test('isFile', () => {
const file = new File([logo], 'logo.svg');
const res = isFile(file);
expect(res).toBe(true);
const res2 = isFile({});
expect(res2).toBe(false);
});
test('isBlob', () => {
const blob = new Blob();
const res = isBlob(blob);
expect(res).toBe(true);
const res2 = isBlob(logo);
expect(res2).toBe(false);
});
});

View File

@ -1,14 +0,0 @@
import { shallowMount } from '@vue/test-utils';
import { describe, expect, test } from 'vitest';
import Footer from './index.vue';
describe('Footer', () => {
test('mount @vue/test-utils', () => {
const wrapper = shallowMount(Footer, {
slots: {
default: '',
},
});
expect(wrapper.text()).toBe('');
});
});

View File

@ -1,8 +1,17 @@
<template>
<a-layout-footer class="footer">MeterSphere</a-layout-footer>
<a-layout-footer class="footer">{{ props.text }}</a-layout-footer>
</template>
<script lang="ts" setup></script>
<script lang="ts" setup>
const props = withDefaults(
defineProps<{
text: string;
}>(),
{
text: 'MeterSphere',
}
);
</script>
<style lang="less" scoped>
.footer {

View File

@ -47,7 +47,3 @@ export function isEmptyObject(obj: any): boolean {
export function isExist(obj: any): boolean {
return obj || obj === 0;
}
export function isWindow(el: any): el is Window {
return el === window;
}