mirror of
https://github.com/tenrok/BBob.git
synced 2026-05-15 11:59:37 +03:00
da6709d437
* feat: use swc.rs instead of babel * BREAKING CHANGE: now we use swc.rs as main bundler and transpiler instead of babel - jest now uses swc - rollup now uses swc * feat: benchmark now separate package with `npm start` and colored output - benchmark as separate package with error throw if package drops performance * feat: all lerna packages now using scripts/pkg-task * feat(github): publish to npm and github registry - when release was created this action automaticly publish packages to npm and github * feat(github): move all from Travis CI to Github Actions - code analysis and tests now using github actions * test: increase tests coverage - add more tests for @bbob/react, @bbob/vue2 and @bbob/parser
84 lines
1.9 KiB
JavaScript
84 lines
1.9 KiB
JavaScript
import { iterate, match, same } from '../src/utils';
|
|
|
|
const stringify = val => JSON.stringify(val);
|
|
|
|
|
|
describe('@bbob/core utils', () => {
|
|
test('iterate', () => {
|
|
const testArr = [{
|
|
one: true,
|
|
content: [{ oneInside: true }]
|
|
}, {
|
|
two: true,
|
|
content: [{ twoInside: true }]
|
|
}];
|
|
|
|
const resultArr = iterate(testArr, node => {
|
|
node.pass = 1;
|
|
|
|
return node;
|
|
});
|
|
|
|
const expected = [
|
|
{
|
|
one: true,
|
|
content: [{ oneInside: true, pass: 1, }],
|
|
pass: 1,
|
|
}, {
|
|
two: true,
|
|
content: [{ twoInside: true, pass: 1, }],
|
|
pass: 1,
|
|
}
|
|
];
|
|
|
|
expect(stringify(resultArr)).toEqual(stringify(expected));
|
|
});
|
|
test('match', () => {
|
|
const testArr = [
|
|
{ tag: 'mytag1', one: 1 },
|
|
{ tag: 'mytag2', two: 1 },
|
|
{ tag: 'mytag3', three: 1 },
|
|
{ tag: 'mytag4', four: 1 },
|
|
{ tag: 'mytag5', five: 1 },
|
|
{ tag: 'mytag6', six: 1 },
|
|
];
|
|
|
|
testArr.match = match;
|
|
|
|
const resultArr = testArr.match([{ tag: 'mytag1' }, { tag: 'mytag2' }], node => {
|
|
node.pass = 1;
|
|
|
|
return node;
|
|
});
|
|
|
|
const expected = [
|
|
{ tag: 'mytag1', one: 1, pass: 1 },
|
|
{ tag: 'mytag2', two: 1, pass: 1 },
|
|
{ tag: 'mytag3', three: 1 },
|
|
{ tag: 'mytag4', four: 1 },
|
|
{ tag: 'mytag5', five: 1 },
|
|
{ tag: 'mytag6', six: 1 },
|
|
];
|
|
|
|
expect(stringify(resultArr)).toEqual(stringify(expected))
|
|
})
|
|
|
|
describe('same', () => {
|
|
test('same not same typeof', () => {
|
|
expect(same(1, {})).toBe(false)
|
|
})
|
|
test('same boolean', () => {
|
|
expect(same(true, true)).toBe(true)
|
|
})
|
|
test('same null', () => {
|
|
expect(same(null, null)).toBe(true)
|
|
})
|
|
test('same array', () => {
|
|
expect(same([1, 2, 3], [1, 2, 3, 4])).toBe(true)
|
|
})
|
|
test('same object', () => {
|
|
expect(same({ foo: true, bar: 'test' }, { foo: true, bar: 'test', ext: true })).toBe(true)
|
|
})
|
|
})
|
|
});
|