1
+ import { assert } from 'chai'
2
+ import CompositeConv from '../dist/CompositeConv'
3
+ import UnitPredConv from '../dist/UnitPredConv'
4
+ import UnitClassConv from '../dist/UnitClassConv'
5
+ import { Foo , isFoo , fooDump , fooRest , foo , Bar , bar , barDump } from './aux'
6
+
7
+
8
+ describe ( 'CompositeConv (subclassing)' , ( ) => {
9
+
10
+ class ConvSubclass extends CompositeConv {
11
+ foo ( ) {
12
+ return 'bar'
13
+ }
14
+ }
15
+
16
+ let fooSpec = {
17
+ class : Foo ,
18
+ dump : ( ) => null
19
+ } ,
20
+ barSpec = {
21
+ class : Bar
22
+ }
23
+
24
+ describe ( '#constructor()' , ( ) => {
25
+
26
+ it ( 'creates working composite converter' , ( ) => {
27
+ let conv = new ConvSubclass ( [ fooSpec , barSpec ] )
28
+ assert . lengthOf ( conv . classConvs , 2 )
29
+ assert . deepEqual ( { $Foo : null } , conv . dump ( foo ) )
30
+ } )
31
+
32
+ it ( 'applies the same validation as parent class' , ( ) => {
33
+ let test = ( ) => new ConvSubclass ( [ { } ] )
34
+ assert . throw ( test , 'Invalid spec, no class, prototype or predicate' )
35
+ } )
36
+
37
+ } )
38
+
39
+ describe ( '#extendWith()' , ( ) => {
40
+
41
+ it ( 'returns new instance of the subclass' , ( ) => {
42
+ let conv1 = new ConvSubclass ( [ fooSpec ] ) ,
43
+ conv2 = conv1 . extendWith ( [ barSpec ] )
44
+
45
+ assert . instanceOf ( conv2 , ConvSubclass )
46
+ assert . notEqual ( conv1 , conv2 )
47
+ assert . lengthOf ( conv2 . classConvs , 2 )
48
+ assert . deepEqual ( { $Bar : 42 } , conv2 . dump ( bar ) )
49
+ } )
50
+
51
+ } )
52
+
53
+ describe ( '#overrideBy()' , ( ) => {
54
+
55
+ it ( 'returns new instance of the subclass' , ( ) => {
56
+ let conv1 = new ConvSubclass ( [ barSpec ] ) ,
57
+ conv2 = conv1 . overrideBy ( [ { class : Bar , dump : ( ) => null } ] )
58
+
59
+ assert . instanceOf ( conv2 , ConvSubclass )
60
+ assert . notEqual ( conv1 , conv2 )
61
+ assert . lengthOf ( conv2 . classConvs , 1 )
62
+ assert . deepEqual ( { $Bar : null } , conv2 . dump ( bar ) )
63
+ } )
64
+
65
+ } )
66
+
67
+ describe ( '#withOptions()' , ( ) => {
68
+
69
+ it ( 'returns new instance of the subclass' , ( ) => {
70
+ let conv1 = new ConvSubclass ( [ barSpec ] ) ,
71
+ conv2 = conv1 . withOptions ( { prefix : '#' } )
72
+
73
+ assert . instanceOf ( conv2 , ConvSubclass )
74
+ assert . notEqual ( conv1 , conv2 )
75
+ assert . deepEqual ( { '#Bar' : 42 } , conv2 . dump ( bar ) )
76
+ } )
77
+
78
+ } )
79
+
80
+ describe ( '#exclude()' , ( ) => {
81
+
82
+ it ( 'returns new instance of the subclass' , ( ) => {
83
+ let conv1 = new ConvSubclass ( [ fooSpec , barSpec ] ) ,
84
+ conv2 = conv1 . exclude ( { class : Bar } )
85
+
86
+ assert . instanceOf ( conv2 , ConvSubclass )
87
+ assert . notEqual ( conv1 , conv2 )
88
+ assert . lengthOf ( conv2 . classConvs , 1 )
89
+ assert . strictEqual ( conv2 . classConvs [ 0 ] . class , Foo )
90
+ } )
91
+
92
+ } )
93
+
94
+ } )
0 commit comments