axios-miniprogram/test/helpers/error.test.ts

22 lines
661 B
TypeScript
Raw Normal View History

2023-03-28 21:32:54 +08:00
import { describe, test, expect } from 'vitest';
2023-04-27 11:08:24 +08:00
import { assert, throwError } from '@/helpers/error';
2023-03-28 21:32:54 +08:00
describe('src/helpers/error.ts', () => {
2023-03-28 21:32:54 +08:00
test('第一个参数为 true 时应该无事发生', () => {
expect(assert(true, '')).toBeUndefined();
});
test('第一个参数为 false 时应该抛出异常', () => {
expect(() => assert(false, '')).toThrowError();
});
test('应该抛出异常', () => {
2023-04-03 21:03:33 +08:00
expect(() => throwError('')).toThrowErrorMatchingInlineSnapshot(
'"[axios-miniprogram]: "',
2023-03-28 21:32:54 +08:00
);
2023-04-03 21:03:33 +08:00
expect(() => throwError('error')).toThrowErrorMatchingInlineSnapshot(
'"[axios-miniprogram]: error"',
);
2023-03-28 21:32:54 +08:00
});
});