-
Notifications
You must be signed in to change notification settings - Fork 880
/
template_test.ts
56 lines (48 loc) · 1.58 KB
/
template_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
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import {suite} from 'uvu';
// eslint-disable-next-line import/extensions
import * as assert from 'uvu/assert';
import type ts from 'typescript';
import {
AnalyzerTestContext,
languages,
setupAnalyzerForTest,
} from '../utils.js';
import {ClassDeclaration} from '../../../lib/model.js';
import {isLitTaggedTemplateExpression} from '../../../lib/lit-html/template.js';
for (const lang of languages) {
const test = suite<AnalyzerTestContext>(`lit-html tests (${lang})`);
test.before((ctx) => {
setupAnalyzerForTest(ctx, lang, 'basic-elements');
});
test('isLitHtmlTemplateTag', ({getModule, analyzer, typescript}) => {
const elementAModule = getModule('element-a')!;
const decl = elementAModule.declarations[0];
// get to the lit-html template tag
const renderMethod = (decl as ClassDeclaration).getMethod('render')!;
const statement = renderMethod.node.body!.statements[0];
assert.is(typescript.isReturnStatement(statement), true);
const returnStatement = statement as ts.ReturnStatement;
assert.ok(returnStatement.expression);
assert.is(
typescript.isTaggedTemplateExpression(returnStatement.expression),
true
);
const expression =
returnStatement.expression as ts.TaggedTemplateExpression;
assert.is(typescript.isIdentifier(expression.tag), true);
assert.is(
isLitTaggedTemplateExpression(
expression,
analyzer.typescript,
analyzer.program.getTypeChecker()
),
true
);
});
test.run();
}