Skip to content

Commit

Permalink
Add tests for custom merge options and callback
Browse files Browse the repository at this point in the history
  • Loading branch information
aedart committed Mar 27, 2024
1 parent 3dcf9de commit 9f8e3d9
Showing 1 changed file with 56 additions and 1 deletion.
57 changes: 56 additions & 1 deletion tests/browser/packages/support/arrays/merge.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { ArrayMergeError, merge } from "@aedart/support/arrays";
import {
ArrayMergeError,
merge,
Merger
} from "@aedart/support/arrays";

describe('@aedart/support/arrays', () => {
describe('merge()', () => {
Expand Down Expand Up @@ -60,5 +64,56 @@ describe('@aedart/support/arrays', () => {
expect(callback)
.toThrowError(ArrayMergeError);
});

it('returns merger object when no args given', () => {
const merger = merge();

expect(merger)
.toBeInstanceOf(Merger);
});

it('can transfer functions', () => {

const fnA = () => false;
const fnB = () => true;

const a = [ fnA ];
const b = [ fnB ];

// --------------------------------------------------------------- //

const result = merge()
.using({ transferFunctions: true })
.of(a, b);

expect(result.length)
.withContext('Incorrect amount of elements in output')
.toBe(2);

expect(result[0])
.withContext('Function A not transferred')
.toBe(fnA);

expect(result[1])
.withContext('Function B not transferred')
.toBe(fnB);
});

it('can apply custom merge callback', () => {

const a = [ 1, 2, 3 ];
const b = [ 4, 5, 6 ];

// --------------------------------------------------------------- //

const result = merge()
.using((element) => {
return element * 2;
})
.of(a, b);

expect(result)
.toEqual([ 2, 4, 6, 8, 10, 12 ]);
});
});
});

0 comments on commit 9f8e3d9

Please sign in to comment.