Skip to content

Commit be40ce2

Browse files
committed
fix(symbol): fix toString() and add tests
1 parent 21eeaaf commit be40ce2

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

src/symbol.spec.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import * as t from './'
2+
import { expect } from 'chai'
3+
import dedent from 'dedent-js'
4+
5+
describe(`t.symbol`, function() {
6+
it(`accepts symbols`, function() {
7+
t.symbol().assert(Symbol('foo'))
8+
t.symbol().assert(Symbol())
9+
})
10+
it(`rejects everything else`, function() {
11+
expect(() => t.symbol().assert(true)).to.throw(
12+
t.RuntimeTypeError,
13+
dedent`
14+
Value must be a symbol
15+
16+
Expected: symbol
17+
18+
Actual Value: true
19+
20+
Actual Type: boolean`
21+
)
22+
expect(() => t.symbol().assert(2)).to.throw(
23+
t.RuntimeTypeError,
24+
dedent`
25+
Value must be a symbol
26+
27+
Expected: symbol
28+
29+
Actual Value: 2
30+
31+
Actual Type: number`
32+
)
33+
})
34+
})
35+
36+
describe(`t.symbol(literal)`, function() {
37+
const foo = Symbol('foo')
38+
const bar = Symbol()
39+
it(`accepts literal value`, function() {
40+
t.symbol(foo).assert(foo)
41+
t.symbol(bar).assert(bar)
42+
})
43+
it(`rejects everything else`, function() {
44+
expect(() => t.symbol(foo).assert(bar)).to.throw(
45+
t.RuntimeTypeError,
46+
dedent`
47+
Value must be exactly typeof Symbol(foo)
48+
49+
Expected: typeof Symbol(foo)
50+
51+
Actual Value: Symbol()
52+
53+
Actual Type: symbol`
54+
)
55+
expect(() => t.symbol(foo).assert(3)).to.throw(
56+
t.RuntimeTypeError,
57+
dedent`
58+
Value must be exactly typeof Symbol(foo)
59+
60+
Expected: typeof Symbol(foo)
61+
62+
Actual Value: 3
63+
64+
Actual Type: number`
65+
)
66+
})
67+
})

src/types/SymbolType.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ export default class SymbolType extends Type<symbol> {
2121
}
2222

2323
toString(): string {
24-
return 'Symbol'
24+
return 'symbol'
2525
}
2626
}

0 commit comments

Comments
 (0)