-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathclass.js
38 lines (34 loc) · 1.04 KB
/
class.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
import inspect from '../lib/index.js'
import { expect } from 'chai'
describe('classes', () => {
class Foo {}
it('returns constructor name with object literal notation for an empty class', () => {
expect(inspect(new Foo())).to.equal('Foo{}')
})
it('returns `<Anonymous Class>{}` for anonymous classes', () => {
const anon = () => class {}
expect(inspect(new (anon())())).to.equal('<Anonymous Class>{}')
})
it('returns toStringTag value as name if present', () => {
class Bar {
get [Symbol.toStringTag]() {
return 'Baz'
}
}
const bar = new Bar()
expect(inspect(bar)).to.equal('Baz{}')
})
describe('properties', () => {
it('inspects and outputs properties ', () => {
const foo = new Foo()
foo.bar = 1
foo.baz = 'hello'
expect(inspect(foo)).to.equal("Foo{ bar: 1, baz: 'hello' }")
})
it('inspects and outputs Symbols', () => {
const foo = new Foo()
foo[Symbol('foo')] = 1
expect(inspect(foo)).to.equal('Foo{ [Symbol(foo)]: 1 }')
})
})
})