/
get-definition-at-position.test.ts
44 lines (41 loc) · 1.19 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
import ts from 'typescript';
import { mark, type Frets } from 'fretted-strings';
import { AdapterFixture } from './testing/adapter-fixture';
import { getDefinitionAtPosition } from './get-definition-at-position';
function createFixture(name: string) {
return new AdapterFixture(name);
}
describe(getDefinitionAtPosition, () => {
const delegateFn = jest.fn(() => []);
it('should works', () => {
const fixture = createFixture('input.ts');
const frets: Frets = {};
fixture.source = mark(
`
const query = \`
query MyQuery {
...MyFragment
%%% ^ %%%
%%% cur %%%
}
fragment MyFragment on Query {
%%% ^ ^ %%%
%%% d1 d2 %%%
__typename
}
\`
`,
frets,
);
const actual = fixture.adapter.getDefinitionAtPosition(delegateFn, 'input.ts', frets.cur.pos);
expect(actual).toMatchObject([
{
fileName: 'input.ts',
textSpan: {
start: frets.d1.pos,
length: frets.d2.pos - frets.d1.pos,
},
},
] as Partial<ts.DefinitionInfo>[]);
});
});