/
get-definition-at-position.test.ts
56 lines (50 loc) · 1.52 KB
/
get-definition-at-position.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { mark, type Frets } from 'fretted-strings';
import { AdapterFixture } from './testing/adapter-fixture';
function createFixture(name: string) {
return new AdapterFixture(name);
}
describe('getDefinitionAtPosition', () => {
const delegateFn = jest.fn(() => []);
it('should not return definition info when the cursor does not point fragment spread', () => {
const fixture = createFixture('input.ts');
const frets: Frets = {};
fixture.source = mark(
`
const query = \`
query MyQuery {
%%% ^ %%%
%%% cur %%%
...MyFragment
}
fragment MyFragment on Query {
__typename
}
\`;
`,
frets,
);
const actual = fixture.adapter.getDefinitionAtPosition(delegateFn, 'input.ts', frets.cur.pos);
expect(actual?.length).toBe(0);
});
it('should return definition of fragment spread under cursor', () => {
const fixture = createFixture('input.ts');
const frets: Frets = {};
fixture.source = mark(
`
const query = \`
query MyQuery {
...MyFragment
%%% ^ %%%
%%% cur %%%
}
fragment MyFragment on Query {
__typename
}
\`;
`,
frets,
);
const actual = fixture.adapter.getDefinitionAtPosition(delegateFn, 'input.ts', frets.cur.pos);
expect(actual?.length).toBe(1);
});
});