From 2f28cd5eb086978b9397f7aef73fcf449819f6d0 Mon Sep 17 00:00:00 2001 From: bendtherules Date: Fri, 20 Sep 2019 11:32:47 +0530 Subject: [PATCH] match - Add testcase - negative check for difference between child and descendant --- test/matchGenerator-basic.spec.tsx | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/matchGenerator-basic.spec.tsx b/test/matchGenerator-basic.spec.tsx index e4ff808..357677f 100644 --- a/test/matchGenerator-basic.spec.tsx +++ b/test/matchGenerator-basic.spec.tsx @@ -94,5 +94,46 @@ describe("matchGenerator", () => { expect((nodes[0] as FiberNodeForComponentClass).type).toBe(C2); expect((nodes[0] as FiberNodeForComponentClass).type).not.toBe(C1); }); + + it("should work for depth=2 class with child selector", () => { + const [C1, C2] = createClassComponents(["C1", "C2"]); + function CRoot() { + return ( + + + + ); + } + const rootNode = mountAndGetRootNode(CRoot, container); + + const nodes = matchAll(rootNode, "C1>C2"); + + // Can't be zero, in any case + expect(nodes.length).not.toBe(0); + // Check that only one node is yielded + expect(nodes.length).toBe(1); + // Check that type is correct + expect((nodes[0] as FiberNodeForComponentClass).type).toBe(C2); + expect((nodes[0] as FiberNodeForComponentClass).type).not.toBe(C1); + }); + + it("should not work with child selector for nth-level descendant", () => { + const [C1, C2, C3] = createClassComponents(["C1", "C2", "C3"]); + function CRoot() { + return ( + + + + + + ); + } + const rootNode = mountAndGetRootNode(CRoot, container); + + const nodes = matchAll(rootNode, "C1>C3"); + + // No matcch found + expect(nodes.length).toBe(0); + }); }); });