|
1 | | -'use strict'; |
2 | | -/* eslint-env mocha */ |
3 | | -var assert = require('assert'); |
| 1 | +import test from 'ava'; |
4 | 2 |
|
5 | | -Object.assign = undefined; |
6 | | -var objectAssign = require('./'); |
| 3 | +Object.assign = require('./'); |
| 4 | +const objectAssign = require('./'); |
7 | 5 |
|
8 | | -it('should have the correct length', function () { |
9 | | - assert.equal(objectAssign.length, 2); |
| 6 | +test('have the correct length', t => { |
| 7 | + t.is(objectAssign.length, 2); |
10 | 8 | }); |
11 | 9 |
|
12 | | -it('should throw when target is not an object', function () { |
13 | | - assert.throws(function () { |
| 10 | +test('throw when target is not an object', t => { |
| 11 | + t.throws(() => { |
14 | 12 | objectAssign(null); |
15 | 13 | }, TypeError); |
16 | | - assert.throws(function () { |
| 14 | + t.throws(() => { |
17 | 15 | objectAssign(undefined); |
18 | 16 | }, TypeError); |
19 | 17 | }); |
20 | 18 |
|
21 | | -it('should objectAssign own enumerable properties from source to target object', function () { |
22 | | - assert.deepEqual(objectAssign({foo: 0}, {bar: 1}), { |
| 19 | +test('objectAssign own enumerable properties from source to target object', t => { |
| 20 | + t.deepEqual(objectAssign({foo: 0}, {bar: 1}), { |
23 | 21 | foo: 0, |
24 | 22 | bar: 1 |
25 | 23 | }); |
26 | | - assert.deepEqual(objectAssign({foo: 0}, null, undefined), {foo: 0}); |
27 | | - assert.deepEqual(objectAssign({foo: 0}, null, undefined, {bar: 1}, null), { |
| 24 | + t.deepEqual(objectAssign({foo: 0}, null, undefined), {foo: 0}); |
| 25 | + t.deepEqual(objectAssign({foo: 0}, null, undefined, {bar: 1}, null), { |
28 | 26 | foo: 0, |
29 | 27 | bar: 1 |
30 | 28 | }); |
31 | 29 | }); |
32 | 30 |
|
33 | | -it('should throw on null/undefined target', function () { |
34 | | - assert.throws(function () { |
| 31 | +test('throw on null/undefined target', t => { |
| 32 | + t.throws(() => { |
35 | 33 | objectAssign(null, {}); |
36 | 34 | }); |
37 | 35 |
|
38 | | - assert.throws(function () { |
| 36 | + t.throws(() => { |
39 | 37 | objectAssign(undefined, {}); |
40 | 38 | }); |
41 | 39 |
|
42 | | - assert.throws(function () { |
| 40 | + t.throws(() => { |
43 | 41 | objectAssign(undefined, undefined); |
44 | 42 | }); |
45 | 43 | }); |
46 | 44 |
|
47 | | -it('should not throw on null/undefined sources', function () { |
48 | | - assert.doesNotThrow(function () { |
| 45 | +test('not throw on null/undefined sources', t => { |
| 46 | + t.notThrows(() => { |
49 | 47 | objectAssign({}, null); |
50 | 48 | }); |
51 | 49 |
|
52 | | - assert.doesNotThrow(function () { |
| 50 | + t.notThrows(() => { |
53 | 51 | objectAssign({}, undefined); |
54 | 52 | }); |
55 | 53 |
|
56 | | - assert.doesNotThrow(function () { |
| 54 | + t.notThrows(() => { |
57 | 55 | objectAssign({}, undefined, null); |
58 | 56 | }); |
59 | 57 | }); |
60 | 58 |
|
61 | | -it('should support multiple sources', function () { |
62 | | - assert.deepEqual(objectAssign({foo: 0}, {bar: 1}, {bar: 2}), { |
| 59 | +test('support multiple sources', t => { |
| 60 | + t.deepEqual(objectAssign({foo: 0}, {bar: 1}, {bar: 2}), { |
63 | 61 | foo: 0, |
64 | 62 | bar: 2 |
65 | 63 | }); |
66 | | - assert.deepEqual(objectAssign({}, {}, {foo: 1}), {foo: 1}); |
| 64 | + t.deepEqual(objectAssign({}, {}, {foo: 1}), {foo: 1}); |
67 | 65 | }); |
68 | 66 |
|
69 | | -it('should only iterate own keys', function () { |
70 | | - var Unicorn = function () {}; |
| 67 | +test('only iterate own keys', t => { |
| 68 | + const Unicorn = function () {}; |
71 | 69 | Unicorn.prototype.rainbows = 'many'; |
72 | | - var unicorn = new Unicorn(); |
| 70 | + const unicorn = new Unicorn(); |
73 | 71 | unicorn.bar = 1; |
74 | 72 |
|
75 | | - assert.deepEqual(objectAssign({foo: 1}, unicorn), { |
| 73 | + t.deepEqual(objectAssign({foo: 1}, unicorn), { |
76 | 74 | foo: 1, |
77 | 75 | bar: 1 |
78 | 76 | }); |
79 | 77 | }); |
80 | 78 |
|
81 | | -it('should return the modified target object', function () { |
82 | | - var target = {}; |
83 | | - var returned = objectAssign(target, {a: 1}); |
84 | | - assert.equal(returned, target); |
| 79 | +test('return the modified target object', t => { |
| 80 | + const target = {}; |
| 81 | + const returned = objectAssign(target, {a: 1}); |
| 82 | + t.is(returned, target); |
85 | 83 | }); |
86 | 84 |
|
87 | | -it('should support `Object.create(null)` objects', function () { |
88 | | - var obj = Object.create(null); |
| 85 | +test('support `Object.create(null)` objects', t => { |
| 86 | + const obj = Object.create(null); |
89 | 87 | obj.foo = true; |
90 | | - assert.deepEqual(objectAssign({}, obj), {foo: true}); |
| 88 | + t.deepEqual(objectAssign({}, obj), {foo: true}); |
91 | 89 | }); |
92 | 90 |
|
93 | | -it('should preserve property order', function () { |
94 | | - var letters = 'abcdefghijklmnopqrst'; |
95 | | - var source = {}; |
96 | | - letters.split('').forEach(function (letter) { |
| 91 | +test('preserve property order', t => { |
| 92 | + const letters = 'abcdefghijklmnopqrst'; |
| 93 | + const source = {}; |
| 94 | + letters.split('').forEach(letter => { |
97 | 95 | source[letter] = letter; |
98 | 96 | }); |
99 | | - var target = objectAssign({}, source); |
100 | | - assert.equal(Object.keys(target).join(''), letters); |
| 97 | + const target = objectAssign({}, source); |
| 98 | + t.is(Object.keys(target).join(''), letters); |
101 | 99 | }); |
102 | 100 |
|
103 | | -it('should accept primitives as target', function () { |
104 | | - var target = objectAssign('abcdefg', {foo: 'bar'}); |
105 | | - var strObj = Object('abcdefg'); |
| 101 | +test('accept primitives as target', t => { |
| 102 | + const target = objectAssign('abcdefg', {foo: 'bar'}); |
| 103 | + const strObj = Object('abcdefg'); |
106 | 104 | strObj.foo = 'bar'; |
107 | | - assert.deepEqual(target, strObj); |
| 105 | + t.deepEqual(target, strObj); |
108 | 106 | }); |
109 | 107 |
|
110 | | -if (typeof Symbol !== 'undefined') { |
111 | | - it('should support symbol properties', function () { |
112 | | - var target = {}; |
113 | | - var source = {}; |
114 | | - var sym = Symbol('foo'); |
| 108 | +if (typeof global.Symbol !== 'undefined') { |
| 109 | + test('support symbol properties', t => { |
| 110 | + const target = {}; |
| 111 | + const source = {}; |
| 112 | + const sym = Symbol('foo'); |
115 | 113 | source[sym] = 'bar'; |
116 | 114 | objectAssign(target, source); |
117 | | - assert.equal(target[sym], 'bar'); |
| 115 | + t.is(target[sym], 'bar'); |
118 | 116 | }); |
119 | 117 |
|
120 | | - it('should only copy enumerable symbols', function () { |
121 | | - var target = {}; |
122 | | - var source = {}; |
123 | | - var sym = Symbol('foo'); |
| 118 | + test('only copy enumerable symbols', t => { |
| 119 | + const target = {}; |
| 120 | + const source = {}; |
| 121 | + const sym = Symbol('foo'); |
124 | 122 | Object.defineProperty(source, sym, { |
125 | 123 | enumerable: false, |
126 | 124 | value: 'bar' |
127 | 125 | }); |
128 | 126 | objectAssign(target, source); |
129 | | - assert.equal(target[sym], undefined); |
| 127 | + t.is(target[sym], undefined); |
130 | 128 | }); |
131 | 129 | } |
0 commit comments