File tree 2 files changed +68
-1
lines changed
2 files changed +68
-1
lines changed Original file line number Diff line number Diff line change
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
+ } )
Original file line number Diff line number Diff line change @@ -21,6 +21,6 @@ export default class SymbolType extends Type<symbol> {
21
21
}
22
22
23
23
toString ( ) : string {
24
- return 'Symbol '
24
+ return 'symbol '
25
25
}
26
26
}
You can’t perform that action at this time.
0 commit comments