Skip to content

Commit f8176b3

Browse files
Chore: improve test coverage for node-event-generator (#8287)
Previonsly, there were insufficient tests for alphabetical selector sorting in the case where selectors had equal specificity. There were also no tests for emitting a selector whose type could not be inferred while exiting the AST.
1 parent 602e9c2 commit f8176b3

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/lib/util/node-event-generator.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ describe("NodeEventGenerator", () => {
260260
"FooStatement",
261261
"[name = 'foo']",
262262
"[name='foo']",
263+
"[name ='foo']",
263264
"Identifier[name='foo']",
264265
"[name='foo'][name.length=3]",
265266
":not(Program, ExpressionStatement)",
@@ -277,13 +278,32 @@ describe("NodeEventGenerator", () => {
277278
["ExpressionStatement > Identifier", ast.body[0].expression], // 0 pseudoclasses, 2 identifiers
278279
["Identifier, ReturnStatement", ast.body[0].expression], // 0 pseudoclasses, 2 identifiers
279280
["[name = 'foo']", ast.body[0].expression], // 1 pseudoclass, 0 identifiers
281+
["[name ='foo']", ast.body[0].expression], // 1 pseudoclass, 0 identifiers
280282
["[name='foo']", ast.body[0].expression], // 1 pseudoclass, 0 identifiers
281283
["ExpressionStatement > [name='foo']", ast.body[0].expression], // 1 attribute, 1 identifier
282284
["Identifier[name='foo']", ast.body[0].expression], // 1 attribute, 1 identifier
283285
[":not(Program, Identifier) > [name.length=3]", ast.body[0].expression], // 1 attribute, 2 identifiers
284286
["[name='foo'][name.length=3]", ast.body[0].expression] // 2 attributes, 0 identifiers
285287
]
286288
);
289+
290+
assertEmissions(
291+
"foo(); bar; baz;",
292+
["CallExpression, [name='bar']"],
293+
ast => [
294+
["CallExpression, [name='bar']", ast.body[0].expression],
295+
["CallExpression, [name='bar']", ast.body[1].expression]
296+
]
297+
);
298+
299+
assertEmissions(
300+
"foo; bar;",
301+
["[name.length=3]:exit"],
302+
ast => [
303+
["[name.length=3]:exit", ast.body[0].expression],
304+
["[name.length=3]:exit", ast.body[1].expression]
305+
]
306+
);
287307
});
288308

289309
describe("parsing an invalid selector", () => {

0 commit comments

Comments
 (0)