Files
eSIM-Tools/tests/simyo/show-toast.test.js
Abner 890e05f27f test: 补充 OAuth、登录、剪贴板与反馈相关单测
修复 sentry-feedback 与 qrcode 断言,新增 clipboard/PKCE/OAuth 回调/AuthHandler/showToast 覆盖。
2026-07-17 20:49:10 +08:00

34 lines
843 B
JavaScript

'use strict';
/**
* Simyo showToast XSS 防护测试
*/
import { showToast } from '../../src/simyo/js/modules/utils.js';
describe('Simyo showToast', () => {
beforeEach(() => {
document.body.innerHTML = '';
jest.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
document.body.innerHTML = '';
});
it('应把消息渲染为文本而不是 HTML', () => {
showToast('<img src=x onerror=alert(1)>');
const toast = document.querySelector('.toast-notification');
expect(toast).toBeTruthy();
expect(toast.querySelector('img[src="x"]')).toBeNull();
expect(toast.textContent).toContain('<img src=x onerror=alert(1)>');
});
it('null/undefined 消息不应抛错', () => {
expect(() => showToast(null)).not.toThrow();
expect(() => showToast(undefined)).not.toThrow();
});
});