22 lines
931 B
TypeScript
22 lines
931 B
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { failureHint } from './failureHint'
|
|
|
|
describe('failureHint', () => {
|
|
it('uses network hint without error', () => {
|
|
expect(failureHint('保存失败')).toBe('保存失败,请检查网络后重试')
|
|
})
|
|
it('classifies TypeError as network', () => {
|
|
const e = new TypeError('Failed to fetch')
|
|
expect(failureHint('请求失败', e)).toBe('请求失败,请检查网络后重试')
|
|
})
|
|
it('classifies 401 as auth', () => {
|
|
expect(failureHint('加载失败', { status: 401 })).toBe('加载失败,请重新登录后再试')
|
|
})
|
|
it('classifies 5xx as server', () => {
|
|
expect(failureHint('保存失败', { status: 502 })).toBe('保存失败,服务器出错,请稍后重试')
|
|
})
|
|
it('keeps Chinese server detail', () => {
|
|
expect(failureHint('保存失败', new Error('重复规则冲突'))).toBe('保存失败:重复规则冲突')
|
|
})
|
|
})
|