Files
NapCatQQ/.pnpm-store/v3/files/7d/34340fe337a9f2551b8a08543ec5da82d7a42af59c05c1175945b4c105403fdeb58efb45ad6e075201bfea94bfba1951f5680f272c174754b217ab3ccad5b8
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

127 lines
3.6 KiB
Plaintext

import { hash } from '../hash';
import { toHash } from '../to-hash';
import { update } from '../update';
import { parse } from '../parse';
import { astish } from '../astish';
jest.mock('../astish', () => ({
astish: jest.fn().mockReturnValue('astish()')
}));
jest.mock('../parse', () => ({
parse: jest.fn().mockReturnValue('parse()')
}));
jest.mock('../to-hash', () => ({
toHash: jest.fn().mockReturnValue('toHash()')
}));
jest.mock('../update', () => ({
update: jest.fn().mockReturnValue('update()')
}));
jest.mock('../astish', () => ({
astish: jest.fn().mockReturnValue('astish()')
}));
jest.mock('../parse', () => ({
parse: jest.fn().mockReturnValue('parse()')
}));
describe('hash', () => {
beforeEach(() => {
toHash.mockClear();
update.mockClear();
parse.mockClear();
astish.mockClear();
});
it('regression', () => {
const res = hash('compiled', 'target');
expect(toHash).toBeCalledWith('compiled');
expect(update).toBeCalledWith('parse()', 'target', undefined, null);
expect(astish).toBeCalledWith('compiled');
expect(parse).toBeCalledWith('astish()', '.toHash()');
expect(res).toEqual('toHash()');
});
it('regression: cache', () => {
const res = hash('compiled', 'target');
expect(toHash).not.toBeCalled();
expect(astish).not.toBeCalled();
expect(parse).not.toBeCalled();
expect(update).toBeCalledWith('parse()', 'target', undefined, null);
expect(res).toEqual('toHash()');
});
it('regression: global', () => {
const res = hash('global', 'target', true);
expect(toHash).toBeCalledWith('global');
expect(astish).not.toBeCalled();
expect(parse).not.toBeCalled();
expect(update).toBeCalledWith('parse()', 'target', undefined, null);
expect(res).toEqual('toHash()');
});
it('regression: global-style-replace', () => {
const res = hash('global', 'target', true);
expect(toHash).not.toBeCalled();
expect(astish).not.toBeCalled();
expect(parse).not.toBeCalled();
expect(update).toBeCalledWith('parse()', 'target', undefined, 'parse()');
expect(res).toEqual('toHash()');
});
it('regression: keyframes', () => {
const res = hash('keyframes', 'target', undefined, undefined, 1);
expect(toHash).toBeCalledWith('keyframes');
expect(astish).not.toBeCalled();
expect(parse).not.toBeCalled();
expect(update).toBeCalledWith('parse()', 'target', undefined, null);
expect(res).toEqual('toHash()');
});
it('regression: object', () => {
const className = Math.random() + 'unique';
toHash.mockReturnValue(className);
const res = hash({ baz: 1 }, 'target');
expect(toHash).toBeCalledWith('baz1');
expect(astish).not.toBeCalled();
expect(parse).toBeCalledWith({ baz: 1 }, '.' + className);
expect(update).toBeCalledWith('parse()', 'target', undefined, null);
expect(res).toEqual(className);
});
it('regression: cache-object', () => {
const className = Math.random() + 'unique';
toHash.mockReturnValue(className);
// Since it's not yet cached
hash({ cacheObject: 1 }, 'target');
expect(toHash).toBeCalledWith('cacheObject1');
toHash.mockClear();
// Different object
hash({ foo: 2 }, 'target');
expect(toHash).toBeCalledWith('foo2');
toHash.mockClear();
// First object should not call .toHash
hash({ cacheObject: 1 }, 'target');
expect(toHash).not.toBeCalled();
});
});