Files
NapCatQQ/.pnpm-store/v3/files/86/562af703feeffc0c83b109c3f2395ac03a90482eb65a30392610e602985b048aaff0dc758db34c0cd6c61ae3090adbf88b8c484d7dec5c858ed6a56ce7206a
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

71 lines
2.0 KiB
Plaintext

import { getSheet } from '../get-sheet';
describe('getSheet', () => {
it('regression', () => {
const target = getSheet();
expect(target.nodeType).toEqual(3);
});
it('custom target', () => {
const custom = document.createElement('div');
const sheet = getSheet(custom);
expect(sheet.nodeType).toEqual(3);
expect(sheet.parentElement.nodeType).toEqual(1);
expect(sheet.parentElement.getAttribute('id')).toEqual('_goober');
});
it('reuse sheet', () => {
const custom = document.createElement('div');
const sheet = getSheet(custom);
const second = getSheet(custom);
expect(sheet === second).toBeTruthy();
});
it('applies nonce from window.__nonce__', () => {
const sheet = getSheet();
const style = sheet.parentElement;
const prevAttr = style.getAttribute('nonce');
const hadAttr = style.hasAttribute('nonce');
const prevNonce = window.__nonce__;
style.removeAttribute('nonce');
delete window.__nonce__;
window.__nonce__ = 'secure-nonce';
getSheet();
expect(style.getAttribute('nonce')).toEqual('secure-nonce');
if (prevAttr != null) style.setAttribute('nonce', prevAttr);
else if (!hadAttr) style.removeAttribute('nonce');
if (prevNonce === undefined) delete window.__nonce__;
else window.__nonce__ = prevNonce;
});
it('server side', () => {
const bkp = global.document;
delete global.document;
expect(() => getSheet()).not.toThrow();
global.document = bkp;
});
it('server side with custom collector', () => {
const bkp = global.document;
const win = global.window;
delete global.document;
delete global.window;
const collector = { data: '' };
expect(collector === getSheet(collector)).toBeTruthy();
global.document = bkp;
global.window = win;
});
});