Skip to content

Commit

Permalink
Adds Union.Types definition error handling unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-ramon committed Jun 12, 2022
1 parent a300a61 commit bdd0ee3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions definition_test.go
Expand Up @@ -706,3 +706,25 @@ func TestTypeSystem_DefinitionExample_IncludesUnionTypesThunk(t *testing.T) {
t.Fatalf("Unexpected result, someUnion should have two unionTypes, has %d", len(unionTypes))
}
}

func TestTypeSystem_DefinitionExample_HandlesInvalidUnionTypes(t *testing.T) {
someUnion := graphql.NewUnion(graphql.UnionConfig{
Name: "SomeUnion",
Types: (graphql.InterfacesThunk)(func() []*graphql.Interface {
return []*graphql.Interface{}
}),
ResolveType: func(p graphql.ResolveTypeParams) *graphql.Object {
return nil
},
})

unionTypes := someUnion.Types()
expected := "Unknown Union.Types type: graphql.InterfacesThunk"

if someUnion.Error().Error() != expected {
t.Fatalf("Unexpected error, got: %v, want: %v", someUnion.Error().Error(), expected)
}
if unionTypes != nil {
t.Fatalf("Unexpected result, got: %v, want: nil", unionTypes)
}
}

0 comments on commit bdd0ee3

Please sign in to comment.