Skip to content

Commit

Permalink
test: Add tests for non-numeric values
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 committed Feb 11, 2021
1 parent 229b944 commit da8689d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ describe("index", () => {
expect(select((elem) => elem.name === "p", dom)).toHaveLength(2);
});

it("should ignore positionals without numbers", () => {
const dom = parseDOM("<div><p>First<p>Second") as Element[];
expect(select(":eq(e)", dom)).toHaveLength(0);
expect(select(":lt(e)", dom)).toHaveLength(0);
expect(select(":gt(e)", dom)).toHaveLength(0);
});

it("should support positionals", () => {
const dom = parseDOM("<div><p>First<p>Second") as Element[];
expect(select("p:first", dom)).toMatchInlineSnapshot(`
Expand All @@ -30,6 +37,17 @@ describe("index", () => {
</p>,
]
`);

expect(select("p:lt(-1)", dom)).toMatchInlineSnapshot(`
Array [
<p>
First
</p>,
<p>
Second
</p>,
]
`);
});

it("should support traversal-first queries", () => {
Expand Down

0 comments on commit da8689d

Please sign in to comment.