-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
89 lines (69 loc) · 2.24 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const assert = require('assert');
const propset = require('.');
describe('propset', function(){
it('should return true when all properties of an object are set', function(done) {
let userObject = {
name: 'Name Property',
email: 'email@props.co',
password: '********'
}
let expected = true;
assert.equal(propset(userObject), expected);
done();
});
it('should return false when any property of an object is not set', function(done) {
let userObject = {
name: 'Name Property',
email: 'email@props.co',
password: null
}
let expected = false;
assert.equal(propset(userObject), expected);
done();
});
it('should return true when property which is not set is passed in second parameter to be skipped', function(done) {
let userObject = {
name: 'Name Property',
email: 'email@props.co',
password: undefined
}
let expected = true;
assert.equal(propset(userObject, 'password'), expected);
done();
});
it('should return true if property which is not set is passed in second parameter as an array to be skipped', function(done) {
let userObject = {
name: null,
email: 'email@props.co',
password: undefined,
age: 18
}
let expected = true;
let skip = ['password', 'name', 'age']
assert.equal(propset(userObject, skip), expected);
done();
});
it('should throw an error if argument passed to be tested is not an object', function(done) {
let userDetailsArray = ['password', 'name', 'age'];
let userId = 1;
let userName = 'Name Property';
assert.throws(() => propset(userDetailsArray), /not an object/);
assert.throws(() => propset(userName), Error);
assert.throws(() => propset(userId), /not an object/);
assert.throws(() => propset(userDetailsArray), Error);
done();
});
it('should throw an error if argument passed as property(ies) to be ignored is not a string or an array', function(done) {
let userObject = {
name: null,
email: 'email@props.co',
password: undefined,
age: 18
}
let propToBeIgnored = 1;
let anotherPropToBeIgnored = {user: 'name', type: 'lib'};
assert.throws(() => propset(userObject, propToBeIgnored), /must be a string or array/);
assert.throws(() => propset(userObject, anotherPropToBeIgnored), Error);
done();
});
})