forked from ChromeDevTools/devtools-frontend
-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathutils.test.js
More file actions
79 lines (67 loc) · 2.79 KB
/
Copy pathutils.test.js
File metadata and controls
79 lines (67 loc) · 2.79 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const parser = require('@typescript-eslint/parser');
const {assert} = require('chai');
const utils = require('../lib/utils.js');
function getParsedExpression(code) {
const parsed = parser.parse(code).body[0];
if (parsed.type !== 'ExpressionStatement') {
throw new Error('Not an expression');
}
return parsed.expression;
}
describe('eslint utils', () => {
describe('isLitHtmlTemplateCall', () => {
it('returns true if the code is Lit.html``', () => {
const code = 'Lit.html`<span>foo</span>`';
const expression = getParsedExpression(code);
const result = utils.isLitHtmlTemplateCall(expression);
assert.strictEqual(result, true);
});
it('returns true if the code is html``', () => {
const code = 'html`<span>foo</span>`';
const expression = getParsedExpression(code);
const result = utils.isLitHtmlTemplateCall(expression);
assert.strictEqual(result, true);
});
it('returns false if the code is Lit.somethingElse``', () => {
const code = 'Lit.somethingElse`<span>foo</span>`';
const expression = getParsedExpression(code);
const result = utils.isLitHtmlTemplateCall(expression);
assert.strictEqual(result, false);
});
it('returns false if the code is another tagged template function``', () => {
const code = 'notLitHtml`<span>foo</span>`';
const expression = getParsedExpression(code);
const result = utils.isLitHtmlTemplateCall(expression);
assert.strictEqual(result, false);
});
});
describe('isLitHtmlRenderCall', () => {
it('returns true if the code is Lit.render()', () => {
const code = 'Lit.render(Lit.html``, this.#shadow)';
const expression = getParsedExpression(code);
const result = utils.isLitHtmlRenderCall(expression);
assert.strictEqual(result, true);
});
it('returns true if the code is render()', () => {
const code = 'render(html``, this.#shadow)';
const expression = getParsedExpression(code);
const result = utils.isLitHtmlRenderCall(expression);
assert.strictEqual(result, true);
});
it('returns false if the code is not render()', () => {
const code = 'notRender(html``, this.#shadow)';
const expression = getParsedExpression(code);
const result = utils.isLitHtmlRenderCall(expression);
assert.strictEqual(result, false);
});
it('returns false if the code is Lit.notRender()', () => {
const code = 'Lit.notRender(html``, this.#shadow)';
const expression = getParsedExpression(code);
const result = utils.isLitHtmlRenderCall(expression);
assert.strictEqual(result, false);
});
});
});