* chore: make aware eslint that we use jest By setting up the jest environment, we no longer need to declare the 'test' global in the configuration. * chore: don't need to import expect, it's a jest environment global * chore: don't need to import expect when creating undefined test
40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
const {uniqueElementsBy} = require('./_30s.js');
|
|
|
|
test('uniqueElementsBy is a Function', () => {
|
|
expect(uniqueElementsBy).toBeInstanceOf(Function);
|
|
});
|
|
|
|
test('uniqueElementsBy works for properties', () => {
|
|
expect(
|
|
uniqueElementsBy(
|
|
[
|
|
{ id: 0, value: 'a' },
|
|
{ id: 1, value: 'b' },
|
|
{ id: 2, value: 'c' },
|
|
{ id: 1, value: 'd' },
|
|
{ id: 0, value: 'e' }
|
|
],
|
|
(a, b) => a.id === b.id
|
|
)
|
|
).toEqual([{ id: 0, value: 'a' }, { id: 1, value: 'b' }, { id: 2, value: 'c' }]);
|
|
});
|
|
|
|
test('uniqueElementsBy works for nested properties', () => {
|
|
expect(
|
|
uniqueElementsBy(
|
|
[
|
|
{ id: 0, value: 'a', n: { p: 0 } },
|
|
{ id: 1, value: 'b', n: { p: 1 } },
|
|
{ id: 2, value: 'c', n: { p: 2 } },
|
|
{ id: 1, value: 'd', n: { p: 0 } },
|
|
{ id: 0, value: 'e', n: { p: 1 } }
|
|
],
|
|
(a, b) => a.id === b.id
|
|
)
|
|
).toEqual([
|
|
{ id: 0, value: 'a', n: { p: 0 } },
|
|
{ id: 1, value: 'b', n: { p: 1 } },
|
|
{ id: 2, value: 'c', n: { p: 2 } }
|
|
]);
|
|
});
|