tests: added tests for nodeAssertion files
ADD
internal/js-ast-utils/assertMultipleNodes.test.ts
+import {test} from "rome";
+import {assertMultipleNodes} from "./assertMultipleNodes";
+import {AnyNode, AnyNodes} from "@internal/ast";
+import {template} from "@internal/js-ast-utils";
+
+const node: AnyNode = template.statement`let a;`;
+const nodeArray: AnyNodes = [node, node];
+
+test(
+ "returns back the same list of nodes",
+ (t) => {
+ let returnedArray = assertMultipleNodes(nodeArray);
+ t.is(returnedArray.length, nodeArray.length);
+ t.looksLike(returnedArray, nodeArray);
+ },
+);
+
+test(
+ "returns an empty list if asserted with undefined",
+ (t) => {
+ t.looksLike(assertMultipleNodes(((undefined as unknown) as AnyNode)), []);
+ },
+);
+
+test(
+ "returns a list with node when asserted with a single node",
+ (t) => {
+ t.looksLike(assertMultipleNodes(node), [node]);
+ },
+);

ADD
internal/js-ast-utils/assertSingleNode.test.ts
+import {test} from "rome";
+import {assertSingleNode} from "./assertSingleNode";
+import {AnyNode, AnyNodes} from "@internal/ast";
+import {template} from "@internal/js-ast-utils";
+
+const node: AnyNode = template.statement`let a`;
+const nodeArray: AnyNodes = [node, node];
+
+test(
+ "returns back the node when asserted with a single node or a list with single node",
+ (t) => {
+ t.looksLike(assertSingleNode(node), node);
+ t.looksLike(assertSingleNode([node]), node);
+ },
+);
+
+test(
+ "fails with error when asserted with list of more than 1 nodes or undefined ",
+ (t) => {
+ t.throws(
+ () => {
+ assertSingleNode(nodeArray);
+ },
+ "Expected node list length of 1 but got 2",
+ );
+ t.throws(
+ () => {
+ assertSingleNode(((undefined as unknown) as AnyNode));
+ },
+ "Expected node or node list but got undefined",
+ );
+ },
+);

ADD
internal/js-ast-utils/assertSingleOrMultipleNodes.test.ts
+import {test} from "rome";
+import {assertSingleOrMultipleNodes} from "./assertSingleOrMultipleNodes";
+import {AnyNode} from "@internal/ast";
+import {template} from "@internal/js-ast-utils";
+
+test(
+ "returns back the asserted value when asserted with a single or multiple node(s)",
+ (t) => {
+ const node: AnyNode = template.statement`let a`;
+ t.looksLike(assertSingleOrMultipleNodes(node), node);
+ t.looksLike(assertSingleOrMultipleNodes([node]), [node]);
+ t.looksLike(assertSingleOrMultipleNodes([node, node]), [node, node]);
+ },
+);
+
+test(
+ "fails with error when asserted with undefined or symbol ",
+ (t) => {
+ t.throws(
+ () => {
+ assertSingleOrMultipleNodes(((Symbol("symbol") as unknown) as AnyNode));
+ },
+ "No symbols expected here",
+ );
+ t.throws(
+ () => {
+ assertSingleOrMultipleNodes(((undefined as unknown) as AnyNode));
+ },
+ "Expected node or node list but got null",
+ );
+ },
+);

tests: added tests for nodeAssertion files (#1093)