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

Loading…
Cancel
Save