-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsimple-objects.js
More file actions
100 lines (86 loc) · 2.72 KB
/
simple-objects.js
File metadata and controls
100 lines (86 loc) · 2.72 KB
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
90
91
92
93
94
95
96
97
98
99
var defaultProperties = {
name: 'someName',
id: 123,
pet: {
type: 'cat',
name: 'Tom'
},
friends: ['Neo', 'Trinity', 'Morfeus']
};
TestFactory.define('user', defaultProperties);
describe('TestFactory', function() {
describe('single object with default properties', function() {
var user;
beforeEach(function() {
user = TestFactory.create('user');
});
it('should create user with default properties', function() {
expect(user).toEqual(defaultProperties);
});
it('should be copy', function() {
expect(user).not.toBe(defaultProperties);
});
});
describe('single object without default properties', function() {
var user, newProperties = {
name: 'John',
pet: {
name: 'Jerry',
type: 'mouse'
}
};
beforeEach(function() {
user = TestFactory.create('user', newProperties);
});
it('should create user with new properties', function() {
expect(user.name).toEqual(newProperties.name);
expect(user.pet).toEqual(newProperties.pet);
expect(user.id).toEqual(defaultProperties.id);
expect(user.friends).toEqual(defaultProperties.friends);
});
it('should be copy', function() {
expect(user).not.toBe(defaultProperties);
expect(user).not.toBe(newProperties);
});
});
describe('collection with default properties', function() {
var users;
beforeEach(function() {
users = TestFactory.createList('user', 3);
});
it('should create users collection with default properties', function() {
expect(users.length).toBe(3);
expect(users[0]).toEqual(defaultProperties);
expect(users[1]).toEqual(defaultProperties);
expect(users[2]).toEqual(defaultProperties);
});
it('should be copy', function() {
expect(users[0]).not.toBe(defaultProperties);
expect(users[1]).not.toBe(defaultProperties);
expect(users[2]).not.toBe(defaultProperties);
});
});
describe('collection without default properties', function() {
var users, newProperties = {
name: 'John',
pet: {
name: 'Jerry',
type: 'mouse'
}
};
beforeEach(function() {
users = TestFactory.createList('user', 3, newProperties);
});
it('should create users collection with new properties', function() {
expect(users.length).toBe(3);
expect(users[0].name).toEqual(newProperties.name);
expect(users[0].pet).toEqual(newProperties.pet);
expect(users[0].id).toEqual(defaultProperties.id);
expect(users[0].friends).toEqual(defaultProperties.friends);
});
it('should be copy', function() {
expect(users[0]).not.toBe(defaultProperties);
expect(users[0]).not.toBe(newProperties);
});
});
});