source: trip-planner-front/node_modules/prr/test.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.8 KB
Line 
1const test = require('tap').test
2 , prr = require('./')
3
4test('test prr(o, key, value) form', function (t) {
5 t.plan(2)
6
7 var o = {}
8 prr(o, 'foo', 'bar')
9 t.equal(o.foo, 'bar', 'correct value')
10 t.deepEqual(
11 Object.getOwnPropertyDescriptor(o, 'foo')
12 , {
13 enumerable : false
14 , configurable : false
15 , writable : false
16 , value : 'bar'
17 }
18 , 'correct property descriptor'
19 )
20 t.end()
21})
22
23test('test prr(o, { key: value }) form', function (t) {
24 t.plan(2)
25
26 var o = {}
27 prr(o, { foo: 'bar' })
28
29 t.equal(o.foo, 'bar', 'correct value')
30 t.deepEqual(
31 Object.getOwnPropertyDescriptor(o, 'foo')
32 , {
33 enumerable : false
34 , configurable : false
35 , writable : false
36 , value : 'bar'
37 }
38 , 'correct property descriptor'
39 )
40 t.end()
41})
42
43test('test multiple key:value pairs', function (t) {
44 var o = { foo: 'bar' }
45
46 prr(o, { one: 'ONE', two: 'TWO', obj: { o: 'o' }})
47
48 t.deepEqual(o, { foo: 'bar' }, 'properties are not enumerable')
49 t.equal(o.one, 'ONE', 'correctly set property')
50 t.equal(o.two, 'TWO', 'correctly set property')
51 t.deepEqual(o.obj, { o: 'o' }, 'correctly set property')
52
53 ;[ 'one', 'two', 'obj' ].forEach(function (p) {
54 t.deepEqual(
55 Object.getOwnPropertyDescriptor(o, p)
56 , {
57 enumerable : false
58 , configurable : false
59 , writable : false
60 , value : p == 'obj' ? { o: 'o' } : p.toUpperCase()
61 }
62 , 'correct property descriptor'
63 )
64 })
65
66 t.end()
67})
68
69test('test descriptor options', function (t) {
70 var o = {}
71
72 prr(o, 'foo', 'bar', {
73 enumerable : true
74 , configurable : false
75 })
76 t.equal(o.foo, 'bar', 'correct value')
77 t.deepEqual(
78 Object.getOwnPropertyDescriptor(o, 'foo')
79 , {
80 enumerable : true
81 , configurable : false
82 , writable : false
83 , value : 'bar'
84 }
85 , 'correct property descriptor'
86 )
87
88 prr(o, 'foo2', 'bar2', {
89 enumerable : true
90 , configurable : true
91 , writable : false
92 })
93 t.equal(o.foo2, 'bar2', 'correct value')
94 t.deepEqual(
95 Object.getOwnPropertyDescriptor(o, 'foo2')
96 , {
97 enumerable : true
98 , configurable : true
99 , writable : false
100 , value : 'bar2'
101 }
102 , 'correct property descriptor'
103 )
104
105 prr(o, 'foo3', 'bar3', {
106 enumerable : true
107 , configurable : true
108 , writable : true
109 })
110 t.equal(o.foo3, 'bar3', 'correct value')
111 t.deepEqual(
112 Object.getOwnPropertyDescriptor(o, 'foo3')
113 , {
114 enumerable : true
115 , configurable : true
116 , writable : true
117 , value : 'bar3'
118 }
119 , 'correct property descriptor'
120 )
121
122 t.end()
123})
124
125
126test('test descriptor options, string form', function (t) {
127 var o = {}
128
129 prr(o, 'foo', 'bar', 'e')
130 t.equal(o.foo, 'bar', 'correct value')
131 t.deepEqual(
132 Object.getOwnPropertyDescriptor(o, 'foo')
133 , {
134 enumerable : true
135 , configurable : false
136 , writable : false
137 , value : 'bar'
138 }
139 , 'correct property descriptor'
140 )
141
142 prr(o, 'foo2', 'bar2', 'ec')
143 t.equal(o.foo2, 'bar2', 'correct value')
144 t.deepEqual(
145 Object.getOwnPropertyDescriptor(o, 'foo2')
146 , {
147 enumerable : true
148 , configurable : true
149 , writable : false
150 , value : 'bar2'
151 }
152 , 'correct property descriptor'
153 )
154
155 prr(o, 'foo3', 'bar3', 'ecw')
156 t.equal(o.foo3, 'bar3', 'correct value')
157 t.deepEqual(
158 Object.getOwnPropertyDescriptor(o, 'foo3')
159 , {
160 enumerable : true
161 , configurable : true
162 , writable : true
163 , value : 'bar3'
164 }
165 , 'correct property descriptor'
166 )
167
168 t.end()
169})
Note: See TracBrowser for help on using the repository browser.