@@ -4,21 +4,46 @@ import { Resolve } from './resolve'
44import { Assert } from '../../assert'
55
66describe ( 'errors/type/Intersect' , ( ) => {
7- const T = Type . Intersect ( [ Type . Object ( { x : Type . Number ( ) } ) , Type . Object ( { y : Type . Number ( ) } ) ] )
87 it ( 'Should pass 0' , ( ) => {
8+ const T = Type . Intersect ( [ Type . Object ( { x : Type . Number ( ) } ) , Type . Object ( { y : Type . Number ( ) } ) ] )
99 const R = Resolve ( T , { x : 1 , y : 1 } )
1010 Assert . IsEqual ( R . length , 0 )
1111 } )
1212 it ( 'Should pass 1' , ( ) => {
13+ const T = Type . Intersect ( [ Type . Object ( { x : Type . Number ( ) } ) , Type . Object ( { y : Type . Number ( ) } ) ] )
1314 const R = Resolve ( T , { x : 1 } )
14- Assert . IsEqual ( R . length , 2 )
15- Assert . IsEqual ( R [ 0 ] . type , ValueErrorType . Intersect )
16- Assert . IsEqual ( R [ 1 ] . type , ValueErrorType . ObjectRequiredProperty )
15+ Assert . IsEqual ( R . length , 3 )
16+ Assert . IsEqual ( R [ 0 ] . type , ValueErrorType . ObjectRequiredProperty )
17+ Assert . IsEqual ( R [ 1 ] . type , ValueErrorType . Number )
18+ Assert . IsEqual ( R [ 2 ] . type , ValueErrorType . Intersect )
1719 } )
1820 it ( 'Should pass 2' , ( ) => {
21+ const T = Type . Intersect ( [ Type . Object ( { x : Type . Number ( ) } ) , Type . Object ( { y : Type . Number ( ) } ) ] )
1922 const R = Resolve ( T , { y : 1 } )
20- Assert . IsEqual ( R . length , 2 )
21- Assert . IsEqual ( R [ 0 ] . type , ValueErrorType . Intersect )
22- Assert . IsEqual ( R [ 1 ] . type , ValueErrorType . ObjectRequiredProperty )
23+ Assert . IsEqual ( R . length , 3 )
24+ Assert . IsEqual ( R [ 0 ] . type , ValueErrorType . ObjectRequiredProperty )
25+ Assert . IsEqual ( R [ 1 ] . type , ValueErrorType . Number )
26+ Assert . IsEqual ( R [ 2 ] . type , ValueErrorType . Intersect )
27+ } )
28+ // ----------------------------------------------------------------
29+ // https://github.com/sinclairzx81/typebox/issues/887
30+ // ----------------------------------------------------------------
31+ it ( 'Should pass 3' , ( ) => {
32+ const A = Type . Intersect ( [ Type . Object ( { x : Type . Number ( ) } ) , Type . Object ( { y : Type . Number ( ) } ) ] )
33+ const B = Type . Intersect ( [ Type . Object ( { x : Type . Number ( ) } ) , Type . Object ( { z : Type . Number ( ) } ) ] )
34+ const T = Type . Intersect ( [ A , B ] )
35+ const R = Resolve ( T , { } )
36+ Assert . IsEqual ( R . length , 11 )
37+ Assert . IsEqual ( R [ 0 ] . type , ValueErrorType . ObjectRequiredProperty )
38+ Assert . IsEqual ( R [ 1 ] . type , ValueErrorType . Number )
39+ Assert . IsEqual ( R [ 2 ] . type , ValueErrorType . ObjectRequiredProperty )
40+ Assert . IsEqual ( R [ 3 ] . type , ValueErrorType . Number )
41+ Assert . IsEqual ( R [ 4 ] . type , ValueErrorType . Intersect )
42+ Assert . IsEqual ( R [ 5 ] . type , ValueErrorType . ObjectRequiredProperty )
43+ Assert . IsEqual ( R [ 6 ] . type , ValueErrorType . Number )
44+ Assert . IsEqual ( R [ 7 ] . type , ValueErrorType . ObjectRequiredProperty )
45+ Assert . IsEqual ( R [ 8 ] . type , ValueErrorType . Number )
46+ Assert . IsEqual ( R [ 9 ] . type , ValueErrorType . Intersect )
47+ Assert . IsEqual ( R [ 10 ] . type , ValueErrorType . Intersect )
2348 } )
2449} )
0 commit comments