merge-strategy.js
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @filedescription Merge Strategy Tests
*/
/* global it, describe, beforeEach */
"use strict";
//-----------------------------------------------------------------------------
// Requirements
//-----------------------------------------------------------------------------
const assert = require("chai").assert;
const { MergeStrategy } = require("../src/");
//-----------------------------------------------------------------------------
// Class
//-----------------------------------------------------------------------------
describe("MergeStrategy", () => {
describe("overwrite()", () => {
it("should overwrite the first value with the second when the second is defined", () => {
const result = MergeStrategy.overwrite(1, 2);
assert.strictEqual(result, 2);
});
it("should overwrite the first value with the second when the second is undefined", () => {
const result = MergeStrategy.overwrite(1, undefined);
assert.strictEqual(result, undefined);
});
});
describe("replace()", () => {
it("should overwrite the first value with the second when the second is defined", () => {
const result = MergeStrategy.replace(1, 2);
assert.strictEqual(result, 2);
});
it("should return the first value when the second is undefined", () => {
const result = MergeStrategy.replace(1, undefined);
assert.strictEqual(result, 1);
});
});
describe("assign()", () => {
it("should merge properties from two objects when called", () => {
const object1 = { foo: 1, bar: 3 };
const object2 = { foo: 2 };
const result = MergeStrategy.assign(object1, object2);
assert.deepStrictEqual(result, {
foo: 2,
bar: 3
});
});
});
});