assertRecord.js
1.59 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
'use strict';
var forEach = require('foreach');
var debug = require('object-inspect');
var assertRecord = require('../../helpers/assertRecord');
var v = require('./values');
module.exports = function assertRecordTests(ES, test) {
test('Property Descriptor', function (t) {
var record = 'Property Descriptor';
forEach(v.nonUndefinedPrimitives, function (primitive) {
t['throws'](
function () { assertRecord(ES, record, 'arg', primitive); },
TypeError,
debug(primitive) + ' is not a Property Descriptor'
);
});
t['throws'](
function () { assertRecord(ES, record, 'arg', { invalid: true }); },
TypeError,
'invalid keys not allowed on a Property Descriptor'
);
t.doesNotThrow(
function () { assertRecord(ES, record, 'arg', {}); },
'empty object is an incomplete Property Descriptor'
);
t.doesNotThrow(
function () { assertRecord(ES, record, 'arg', v.accessorDescriptor()); },
'accessor descriptor is a Property Descriptor'
);
t.doesNotThrow(
function () { assertRecord(ES, record, 'arg', v.mutatorDescriptor()); },
'mutator descriptor is a Property Descriptor'
);
t.doesNotThrow(
function () { assertRecord(ES, record, 'arg', v.dataDescriptor()); },
'data descriptor is a Property Descriptor'
);
t.doesNotThrow(
function () { assertRecord(ES, record, 'arg', v.genericDescriptor()); },
'generic descriptor is a Property Descriptor'
);
t['throws'](
function () { assertRecord(ES, record, 'arg', v.bothDescriptor()); },
TypeError,
'a Property Descriptor can not be both a Data and an Accessor Descriptor'
);
t.end();
});
};