@@ -52,11 +52,13 @@ describe("UnionType component", () => {
5252 </ gql . ObjectType >
5353 < UnionType type = { mutatedUnion } />
5454 </ > ,
55+ { unionMembers : new Map ( [ [ mutatedUnion , mutation . memberNames ] ] ) } ,
5556 ) ;
5657
5758 expect ( sdl ) . toContain ( "union Pet =" ) ;
58- expect ( sdl ) . toContain ( "Cat" ) ;
59- expect ( sdl ) . toContain ( "Dog" ) ;
59+ for ( const member of mutation . memberNames ) {
60+ expect ( sdl ) . toContain ( member ) ;
61+ }
6062 } ) ;
6163
6264 it ( "renders a union with doc comment description" , async ( ) => {
@@ -84,6 +86,7 @@ describe("UnionType component", () => {
8486 </ gql . ObjectType >
8587 < UnionType type = { mutatedUnion } />
8688 </ > ,
89+ { unionMembers : new Map ( [ [ mutatedUnion , mutation . memberNames ] ] ) } ,
8790 ) ;
8891
8992 expect ( sdl ) . toContain ( "The result of an operation" ) ;
@@ -118,12 +121,13 @@ describe("UnionType component", () => {
118121 </ gql . ObjectType >
119122 < UnionType type = { mutatedUnion } />
120123 </ > ,
124+ { unionMembers : new Map ( [ [ mutatedUnion , mutation . memberNames ] ] ) } ,
121125 ) ;
122126
123127 expect ( sdl ) . toContain ( "union Shape =" ) ;
124- expect ( sdl ) . toContain ( "Circle" ) ;
125- expect ( sdl ) . toContain ( "Square" ) ;
126- expect ( sdl ) . toContain ( "Triangle" ) ;
128+ for ( const member of mutation . memberNames ) {
129+ expect ( sdl ) . toContain ( member ) ;
130+ }
127131 } ) ;
128132
129133 it ( "references wrapper type names for scalar variants" , async ( ) => {
@@ -138,23 +142,27 @@ describe("UnionType component", () => {
138142 const mutation = engine . mutateUnion ( Mixed , GraphQLTypeContext . Output ) ;
139143 const mutatedUnion = assertUnionResult ( mutation ) ;
140144
141- // Register Cat and the wrapper type that the union will reference
145+ // Register the mutation's wrapper models so buildSchema resolves the members.
142146 const sdl = renderComponentToSDL (
143147 tester . program ,
144148 < >
145149 < gql . ObjectType name = "Cat" >
146150 < gql . Field name = "name" type = { gql . String } nonNull />
147151 </ gql . ObjectType >
148- < gql . ObjectType name = "MixedTextUnionVariant" >
149- < gql . Field name = "value" type = { gql . String } nonNull />
150- </ gql . ObjectType >
152+ { mutation . wrapperModels . map ( ( wrapper ) => (
153+ < gql . ObjectType name = { wrapper . name } >
154+ < gql . Field name = "value" type = { gql . String } nonNull />
155+ </ gql . ObjectType >
156+ ) ) }
151157 < UnionType type = { mutatedUnion } />
152158 </ > ,
159+ { unionMembers : new Map ( [ [ mutatedUnion , mutation . memberNames ] ] ) } ,
153160 ) ;
154161
155- // Scalar variant should reference wrapper type name
162+ // Every member the engine reported should land in the SDL.
156163 expect ( sdl ) . toContain ( "union Mixed =" ) ;
157- expect ( sdl ) . toContain ( "MixedTextUnionVariant" ) ;
158- expect ( sdl ) . toContain ( "Cat" ) ;
164+ for ( const member of mutation . memberNames ) {
165+ expect ( sdl ) . toContain ( member ) ;
166+ }
159167 } ) ;
160168} ) ;
0 commit comments