Skip to content

Commit

Permalink
more low level unit tests for definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed May 19, 2024
1 parent 7e32382 commit 70707b9
Showing 1 changed file with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,29 @@ describe('GraphQLLanguageService', () => {
getProjectForFile(uri: string) {
return this.getGraphQLConfig().getProjectForFile(uri);
},

getFragmentDefinitions() {
const definitions = new Map();
definitions.set('TestFragment', {
filePath: 'fake file path',
content: 'fake file content',
definition: {
kind: 'FragmentDefinition',
name: {
value: 'TestFragment',
},
loc: {
start: 293,
end: 335,
},
},
});
return definitions;
},
// setting the defs here in duplicate as with object types below
// leads to duplicates, perhaps related to a bug, or perhaps just a test bug?
getFragmentDependenciesForAST() {
return [];
},
getObjectTypeDefinitions() {
const definitions = new Map();

Expand Down Expand Up @@ -177,6 +199,23 @@ describe('GraphQLLanguageService', () => {
expect(definitionQueryResult?.definitions.length).toEqual(1);
});

it('runs definition service on fragment definition', async () => {
const definitionQueryResult = await languageService.getDefinition(
'fragment TestFragment on Human { name }',
{ line: 0, character: 14 } as Position,
'./queries/definitionQuery.graphql',
);
expect(definitionQueryResult?.definitions.length).toEqual(1);
});
it('runs definition service on fragment spread', async () => {
const definitionQueryResult = await languageService.getDefinition(
'fragment TestFragment on Human { name }\nquery { ...TestFragment }',
{ line: 1, character: 14 } as Position,
'./queries/definitionQuery.graphql',
);
expect(definitionQueryResult?.definitions.length).toEqual(1);
});

it('runs definition service on field as expected', async () => {
const definitionQueryResult = await languageService.getDefinition(
'query XXX { human { name } }',
Expand Down

0 comments on commit 70707b9

Please sign in to comment.