source: node_modules/xtend/test.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[d24f17c]1var test = require("tape")
2var extend = require("./")
3var mutableExtend = require("./mutable")
4
5test("merge", function(assert) {
6 var a = { a: "foo" }
7 var b = { b: "bar" }
8
9 assert.deepEqual(extend(a, b), { a: "foo", b: "bar" })
10 assert.end()
11})
12
13test("replace", function(assert) {
14 var a = { a: "foo" }
15 var b = { a: "bar" }
16
17 assert.deepEqual(extend(a, b), { a: "bar" })
18 assert.end()
19})
20
21test("undefined", function(assert) {
22 var a = { a: undefined }
23 var b = { b: "foo" }
24
25 assert.deepEqual(extend(a, b), { a: undefined, b: "foo" })
26 assert.deepEqual(extend(b, a), { a: undefined, b: "foo" })
27 assert.end()
28})
29
30test("handle 0", function(assert) {
31 var a = { a: "default" }
32 var b = { a: 0 }
33
34 assert.deepEqual(extend(a, b), { a: 0 })
35 assert.deepEqual(extend(b, a), { a: "default" })
36 assert.end()
37})
38
39test("is immutable", function (assert) {
40 var record = {}
41
42 extend(record, { foo: "bar" })
43 assert.equal(record.foo, undefined)
44 assert.end()
45})
46
47test("null as argument", function (assert) {
48 var a = { foo: "bar" }
49 var b = null
50 var c = void 0
51
52 assert.deepEqual(extend(b, a, c), { foo: "bar" })
53 assert.end()
54})
55
56test("mutable", function (assert) {
57 var a = { foo: "bar" }
58
59 mutableExtend(a, { bar: "baz" })
60
61 assert.equal(a.bar, "baz")
62 assert.end()
63})
64
65test("null prototype", function(assert) {
66 var a = { a: "foo" }
67 var b = Object.create(null)
68 b.b = "bar";
69
70 assert.deepEqual(extend(a, b), { a: "foo", b: "bar" })
71 assert.end()
72})
73
74test("null prototype mutable", function (assert) {
75 var a = { foo: "bar" }
76 var b = Object.create(null)
77 b.bar = "baz";
78
79 mutableExtend(a, b)
80
81 assert.equal(a.bar, "baz")
82 assert.end()
83})
84
85test("prototype pollution", function (assert) {
86 var a = {}
87 var maliciousPayload = '{"__proto__":{"oops":"It works!"}}'
88
89 assert.strictEqual(a.oops, undefined)
90 extend({}, maliciousPayload)
91 assert.strictEqual(a.oops, undefined)
92 assert.end()
93})
94
95test("prototype pollution mutable", function (assert) {
96 var a = {}
97 var maliciousPayload = '{"__proto__":{"oops":"It works!"}}'
98
99 assert.strictEqual(a.oops, undefined)
100 mutableExtend({}, maliciousPayload)
101 assert.strictEqual(a.oops, undefined)
102 assert.end()
103})
Note: See TracBrowser for help on using the repository browser.