-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
source-files.test.ts
37 lines (29 loc) · 979 Bytes
/
source-files.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
import * as ts from 'typescript';
import { getCodeText, isSourceFile } from '../../src/source-files';
describe('isSourceFile', () => {
it.each([null, undefined, {}, { getFullText: (): string => '', text: '' }])(
`returns false when given %j`,
input => {
expect(isSourceFile(input)).toBe(false);
},
);
it('returns true when given a real source file', () => {
const input = ts.createSourceFile('test.ts', '', ts.ScriptTarget.ESNext);
expect(isSourceFile(input)).toBe(true);
});
});
describe('getCodeText', () => {
it('returns the code when code is provided as a string', () => {
const code = '// Hello world';
expect(getCodeText(code)).toBe(code);
});
it('returns the code when code is provided as a source file', () => {
const code = '// Hello world';
const sourceFile = ts.createSourceFile(
'test.ts',
code,
ts.ScriptTarget.ESNext,
);
expect(getCodeText(sourceFile)).toBe(code);
});
});