-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
56 lines (52 loc) · 1.52 KB
/
test.js
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
'use strict';
require('mocha');
var assert = require('assert');
var arrayRefactor = require('./');
describe('array-refactor', () => {
it('should not modify array:', () => {
let defaultArr = {
"index": 0,
"userToken": "93507d5b-64f3-4a74-ba91-4e3491049193",
"isActive": false,
"balance": "$2,495.32",
"picture": "http://placehold.it/32x32"
}
let arr = {
"index": 0,
"userToken": "93507d5b-64f3-4a74-ba91-4e3491049193",
"isActive": false,
"balance": "$2,495.32",
"picture": "http://placehold.it/32x32"
};
assert.deepEqual(arrayRefactor.pop([arr], ['password']), [defaultArr]);
assert.deepEqual(arrayRefactor.pop([arr], "password"), [defaultArr]);
assert.deepEqual(arrayRefactor.pop(arr, ["password"]), defaultArr);
assert.deepEqual(arrayRefactor.pop(arr, "password"), defaultArr);
});
it('deep search for key and modify array or object:', () => {
let arr = [
[
[
{
name: "srujal",
password: '124343'
}
]
]
]
let output = [
[
[
{
name: 'srujal'
}
]
]
]
assert.deepEqual(arrayRefactor.pop(arr, 'password'), output);
});
it('should return the same array if no other args are passed or pass second args which is not in:', () => {
assert.deepEqual(arrayRefactor.pop(['a', 'b', 'c']), ['a', 'b', 'c']);
assert.deepEqual(arrayRefactor.pop(['a', 'b', 'c'], "second"), ['a', 'b', 'c']);
});
});