|
2 | 2 |
|
3 | 3 | const should = require('should'),
|
4 | 4 | sinon = require('sinon'),
|
5 |
| - test = require('ava').test, |
6 |
| - objOps = require('../../lib/objectOps'); |
7 |
| - |
8 |
| -const ObjectOps = objOps.ObjectOps; |
9 |
| - |
10 |
| -test('#constructor can initialize from another object', () => { |
11 |
| - should(new ObjectOps({ a: 1, b: { c: 2 } })) |
12 |
| - .containEql({ a: 1, b: { c: 2 } }); |
| 5 | + { test } = require('ava'), |
| 6 | + { ObjectOps } = require('../../lib/objectOps'); |
| 7 | + |
| 8 | +test('#constructor can initialize from another object', t => { |
| 9 | + t.deepEqual( |
| 10 | + new ObjectOps({ a: 1, b: { c: 2 } }), |
| 11 | + { a: 1, b: { c: 2 } } |
| 12 | + ); |
13 | 13 | });
|
14 | 14 |
|
15 |
| -test('#clone returns a deep copy of the object', () => { |
| 15 | +test('#clone returns a deep copy of the object', t => { |
16 | 16 | const base = new ObjectOps({ a: 1, b: { c: 2 } });
|
17 | 17 | const clone = base.clone();
|
18 | 18 |
|
19 |
| - should(base).eql(clone); |
20 |
| - should(base).not.equal(clone); |
21 |
| - should(base.b).not.equal(clone.b); |
| 19 | + t.deepEqual(base, clone); |
| 20 | + t.not(base, clone); |
| 21 | + t.not(base.b, clone.b); |
22 | 22 | });
|
23 | 23 |
|
24 |
| -test('#move copies the value from one path to another', () => { |
25 |
| - should(new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'b.d')) |
26 |
| - .eql(new ObjectOps({ a: 1, b: { d: 2 } })); |
| 24 | +test('#move copies the value from one path to another', t => { |
| 25 | + t.deepEqual( |
| 26 | + new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'b.d'), |
| 27 | + new ObjectOps({ a: 1, b: { d: 2 } }) |
| 28 | + ); |
27 | 29 | });
|
28 | 30 |
|
29 |
| -test('#move errors out if source path does not exist', () => { |
30 |
| - should(() => new ObjectOps({ a: 1, b: { c: 2 } }).move('c.c', 'b.c')) |
31 |
| - .throw(TypeError, { message: 'Path is invalid at depth 0.' }); |
| 31 | +test('#move errors out if source path does not exist', t => { |
| 32 | + t.throws( |
| 33 | + () => new ObjectOps({ a: 1, b: { c: 2 } }).move('c.c', 'b.c'), |
| 34 | + TypeError, |
| 35 | + 'Path is invalid at depth 0.' |
| 36 | + ); |
32 | 37 | });
|
33 | 38 |
|
34 |
| -test('#move builds the new path as needed', () => { |
35 |
| - should(new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'c.b')) |
36 |
| - .containEql({ c: { b: 2 } }); |
| 39 | +test('#move builds the new path as needed', t => { |
| 40 | + t.deepEqual( |
| 41 | + new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'c.b').c, |
| 42 | + { b: 2 } |
| 43 | + ); |
37 | 44 | });
|
38 | 45 |
|
39 |
| -test('#move fails if destination path exists and is not traversable', () => { |
40 |
| - should(() => new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'a.b')) |
41 |
| - .throw(TypeError, { message: 'Path not traversable on step "a". Expected Object, got "1".' }); |
| 46 | +test('#move fails if destination path exists and is not traversable', t => { |
| 47 | + t.throws( |
| 48 | + () => new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'a.b'), |
| 49 | + TypeError, |
| 50 | + 'Path not traversable on step "a". Expected Object, got "1".' |
| 51 | + ); |
42 | 52 | });
|
43 | 53 |
|
44 |
| -test('#move removes the source value', () => { |
45 |
| - should(new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'c.b')) |
46 |
| - .containEql({ b: {} }); |
| 54 | +test('#move removes the source value', t => { |
| 55 | + t.deepEqual( |
| 56 | + new ObjectOps({ a: 1, b: { c: 2 } }).move('b.c', 'c.b').b, |
| 57 | + {} |
| 58 | + ); |
47 | 59 | });
|
48 | 60 |
|
49 |
| -test('#move leaves the object untouched if an error occurs', () => { |
| 61 | +test('#move leaves the object untouched if an error occurs', t => { |
50 | 62 | const obj = new ObjectOps({ a: 1, b: { c: 2 } });
|
51 | 63 |
|
52 | 64 | try {
|
53 | 65 | obj.move('b.c', 'a.b');
|
54 | 66 | } catch (err) {
|
55 |
| - should(obj).eql(new ObjectOps({ a: 1, b: { c: 2 } })); |
| 67 | + t.deepEqual(obj, new ObjectOps({ a: 1, b: { c: 2 } })); |
56 | 68 | }
|
57 | 69 | });
|
58 | 70 |
|
59 |
| -test('#remove removes a path from the object', () => { |
60 |
| - should(new ObjectOps({ a: 1, b: { c: 2 } }).remove('b.c')) |
61 |
| - .eql(new ObjectOps({ a: 1, b: { } })); |
| 71 | +test('#remove removes a path from the object', t => { |
| 72 | + t.deepEqual( |
| 73 | + new ObjectOps({ a: 1, b: { c: 2 } }).remove('b.c'), |
| 74 | + new ObjectOps({ a: 1, b: { } }) |
| 75 | + ); |
62 | 76 | });
|
63 | 77 |
|
64 |
| -test('#remove errors out if path doesn\'t exist', () => { |
65 |
| - should(() => new ObjectOps({ a: 1, b: { c: 2 } }).remove('a.b')) |
66 |
| - .throw(TypeError, { message: 'Expected object, got "1".' }); |
| 78 | +test('#remove errors out if path doesn\'t exist', t => { |
| 79 | + t.throws( |
| 80 | + () => new ObjectOps({ a: 1, b: { c: 2 } }).remove('a.b'), |
| 81 | + TypeError, |
| 82 | + 'Expected object, got "1".' |
| 83 | + ); |
67 | 84 | });
|
68 | 85 |
|
69 |
| -test('#remove takes multiple paths', () => { |
70 |
| - should(new ObjectOps({ a: 1, b: { c: 2 } }).remove('a', 'b')) |
71 |
| - .eql(new ObjectOps()); |
| 86 | +test('#remove takes multiple paths', t => { |
| 87 | + t.deepEqual( |
| 88 | + new ObjectOps({ a: 1, b: { c: 2 } }).remove('a', 'b'), |
| 89 | + new ObjectOps() |
| 90 | + ); |
72 | 91 | });
|
73 | 92 |
|
74 |
| -test('#transform calls a function with the value at path', () => { |
| 93 | +test('#transform calls a function with the value at path', t => { |
75 | 94 | const spy = sinon.spy(() => {});
|
76 | 95 | new ObjectOps({ a: 1, b: { c: 2 } }).transform('b.c', spy);
|
77 | 96 | sinon.assert.calledWith(spy, 2);
|
| 97 | + t.pass(); |
78 | 98 | });
|
79 | 99 |
|
80 |
| -test('#transform sets the value returned from the function', () => { |
81 |
| - should(new ObjectOps({ a: 1, b: { c: 2 } }).transform('b.c', () => 3)) |
82 |
| - .eql(new ObjectOps({ a: 1, b: { c: 3 } })); |
| 100 | +test('#transform sets the value returned from the function', t => { |
| 101 | + t.deepEqual( |
| 102 | + new ObjectOps({ a: 1, b: { c: 2 } }).transform('b.c', () => 3), |
| 103 | + new ObjectOps({ a: 1, b: { c: 3 } }) |
| 104 | + ); |
83 | 105 | });
|
84 | 106 |
|
85 |
| -test('#transform errors out if path doesn\'t exist', () => { |
86 |
| - should(() => new ObjectOps({ a: 1, b: { c: 2 } }).transform('a.b', () => {})) |
87 |
| - .throw(TypeError, { message: 'Path is invalid at depth 0.' }); |
| 107 | +test('#transform errors out if path doesn\'t exist', t => { |
| 108 | + t.throws( |
| 109 | + () => new ObjectOps({ a: 1, b: { c: 2 } }).transform('a.b', () => {}), |
| 110 | + TypeError, |
| 111 | + 'Path is invalid at depth 0.' |
| 112 | + ); |
88 | 113 | });
|
0 commit comments