Browse Source

test: fix failing CI test and improve test assertions in requestErrorConfig

- Fix 'should append token to URL' test that expected non-existent token
  attachment logic (source code has it commented out); now tests actual
  pass-through behavior
- Add expect.assertions(5) to try/catch BizError test to prevent false
  positive if errorThrower doesn't throw
- Move navigator.onLine restoration into finally block to prevent state
  leak on assertion failure
- Replace tautological REDIRECT assertion with meaningful verification
  that no message/notification is triggered

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
pull/11847/head
afc163 4 months ago
parent
commit
f975cccdd7
  1. 36
      src/requestErrorConfig.test.ts

36
src/requestErrorConfig.test.ts

@ -63,6 +63,7 @@ describe('requestErrorConfig', () => {
showType: 3,
};
expect.assertions(5);
try {
errorThrower(response);
} catch (error: any) {
@ -157,9 +158,10 @@ describe('requestErrorConfig', () => {
errorHandler(error, {});
// Note: In jsdom/happy-dom, window.location.href assignment may not work as expected
// This test verifies the code path is executed without error
expect(error.info.showType).toBe(9);
// REDIRECT 分支不应触发任何消息/通知提示
expect(message.warning).not.toHaveBeenCalled();
expect(message.error).not.toHaveBeenCalled();
expect(notification.open).not.toHaveBeenCalled();
});
it('should handle default case for unknown showType', () => {
@ -198,16 +200,18 @@ describe('requestErrorConfig', () => {
value: false,
});
errorHandler(error, {});
expect(message.error).toHaveBeenCalledWith(
'Network unavailable. Please check your connection and try again.',
);
Object.defineProperty(navigator, 'onLine', {
writable: true,
value: originalOnLine,
});
try {
errorHandler(error, {});
expect(message.error).toHaveBeenCalledWith(
'Network unavailable. Please check your connection and try again.',
);
} finally {
Object.defineProperty(navigator, 'onLine', {
writable: true,
value: originalOnLine,
});
}
});
it('should handle request error with no response', () => {
@ -240,7 +244,7 @@ describe('requestErrorConfig', () => {
method?: string;
}) => { url?: string };
it('should append token to URL', () => {
it('should pass through config without modification', () => {
const config = {
url: 'https://api.example.com/users',
method: 'GET',
@ -248,7 +252,9 @@ describe('requestErrorConfig', () => {
const result = interceptor(config);
expect(result.url).toBe('https://api.example.com/users?token=123');
// Token attachment is intentionally commented out in the source;
// interceptor currently returns config as-is
expect(result.url).toBe('https://api.example.com/users');
});
it('should handle URL without config', () => {

Loading…
Cancel
Save