-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
77 lines (63 loc) · 2.6 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
'use strict'
const assert = require('assert')
const getClassChain = require('.')
class A {}
class B {}
class B1 extends B {}
describe('getClassChain()', function () {
it('should return an empty array for primitives', function () {
assert.strictEqual(getClassChain('test').length, 0)
})
it('should return an empty array for a plain object', function () {
assert.strictEqual(getClassChain({}).length, 0)
})
it('should return an empty array for an object with a null prototype', function () {
assert.strictEqual(getClassChain(Object.create(null)).length, 0)
})
it('should return an empty array for a nameless function', function () {
assert.strictEqual(getClassChain(function () {}).length, 0)
})
it('should return the wrapper class for a wrapped primitive', function () {
const classes = getClassChain(new String('test')) // eslint-disable-line no-new-wrappers
assert.strictEqual(classes.length, 1)
assert.strictEqual(classes[0], String)
})
it('should return single class when given non-extending class', function () {
const classes = getClassChain(A)
assert.strictEqual(classes.length, 1)
assert.strictEqual(classes[0], A)
})
it('should return single class when given instance of non-extending class', function () {
const classes = getClassChain(new A())
assert.strictEqual(classes.length, 1)
assert.strictEqual(classes[0], A)
})
it('should return multiple classes when given extending class', function () {
const classes = getClassChain(B1)
assert.strictEqual(classes.length, 2)
assert.strictEqual(classes[0], B1)
assert.strictEqual(classes[1], B)
})
it('should return multiple classes when given instance of extending class', function () {
const classes = getClassChain(new B1())
assert.strictEqual(classes.length, 2)
assert.strictEqual(classes[0], B1)
assert.strictEqual(classes[1], B)
})
})
describe('getClassChain.names()', function () {
it('should return an empty array for invalid input', function () {
assert.strictEqual(getClassChain.names('test').length, 0)
})
it('should return the wrapper class name for a wrapped primitive', function () {
const classes = getClassChain.names(new String('test')) // eslint-disable-line no-new-wrappers
assert.strictEqual(classes.length, 1)
assert.strictEqual(classes[0], 'String')
})
it('should return multiple class names when given instance of extending class', function () {
const classes = getClassChain.names(new B1())
assert.strictEqual(classes.length, 2)
assert.strictEqual(classes[0], 'B1')
assert.strictEqual(classes[1], 'B')
})
})