Files
NapCatQQ/.pnpm-store/v3/files/b0/664fdb84dec8b7aca83f3d1dcef5833bee93523a2bc231a5e434e69a32ea33890f9268d7dc5c7e5e08fb0c3a78d3df399dc3a4cfb8a6f7596fc33c2370917b
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

92 lines
2.2 KiB
Plaintext

import test from 'tape';
import attributesComparator from '../../../src/util/attributesComparator';
import JSXAttributeMock from '../../../__mocks__/JSXAttributeMock';
import JSXElementMock from '../../../__mocks__/JSXElementMock';
test('attributesComparator', (t) => {
t.equal(
attributesComparator(),
true,
'baseAttributes are undefined and attributes are undefined -> true',
);
t.equal(
attributesComparator([], []),
true,
'baseAttributes are empty and attributes are empty -> true',
);
t.equal(
attributesComparator([], [
JSXAttributeMock('foo', 0),
JSXAttributeMock('bar', 'baz'),
]),
true,
'baseAttributes are empty and attributes have values -> true',
);
const baseAttributes = [
{
name: 'biz',
value: 1,
}, {
name: 'fizz',
value: 'pop',
}, {
name: 'fuzz',
value: 'lolz',
},
];
t.equal(
attributesComparator(baseAttributes, []),
false,
'baseAttributes have values and attributes are empty -> false',
);
t.equal(
attributesComparator(baseAttributes, [
JSXElementMock(),
JSXAttributeMock('biz', 2),
JSXAttributeMock('ziff', 'opo'),
JSXAttributeMock('far', 'lolz'),
]),
false,
'baseAttributes have values and attributes have values, and the values are different -> false',
);
t.equal(
attributesComparator(baseAttributes, [
JSXAttributeMock('biz', 1),
JSXAttributeMock('fizz', 'pop'),
JSXAttributeMock('goo', 'gazz'),
]),
false,
'baseAttributes have values and attributes have values, and the values are a subset -> false',
);
t.equal(
attributesComparator(baseAttributes, [
JSXAttributeMock('biz', 1),
JSXAttributeMock('fizz', 'pop'),
JSXAttributeMock('fuzz', 'lolz'),
]),
true,
'baseAttributes have values and attributes have values, and the values are the same -> true',
);
t.equal(
attributesComparator(baseAttributes, [
JSXAttributeMock('biz', 1),
JSXAttributeMock('fizz', 'pop'),
JSXAttributeMock('fuzz', 'lolz'),
JSXAttributeMock('dar', 'tee'),
]),
true,
'baseAttributes have values and attributes have values, and the values are a superset -> true',
);
t.end();
});