From 7ce8ee17786c18f9fecf5d3ec11bf27f1438a45c Mon Sep 17 00:00:00 2001 From: bendtherules Date: Sun, 21 Jul 2019 09:18:16 +0530 Subject: [PATCH] Add testcase - depth-7-nested-2 as a more nested case --- test/sample-components/depth-7-nested-2.tsx | 33 +++++++++++++++++++++ test/traverse-nested.spec.tsx | 26 +++++++++++----- 2 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 test/sample-components/depth-7-nested-2.tsx diff --git a/test/sample-components/depth-7-nested-2.tsx b/test/sample-components/depth-7-nested-2.tsx new file mode 100644 index 0000000..55c999c --- /dev/null +++ b/test/sample-components/depth-7-nested-2.tsx @@ -0,0 +1,33 @@ +// import * as PropTypes from "prop-types"; +import * as React from "react"; + +class CDepth7Nested2 extends React.Component { + render() { + const someValue = 5; + + return ( +
+ +
+ ); + } +} + +class CDepth4 extends React.Component { + render() { + return ( +
+ + +
+ ); + } +} + +class CDepth1 extends React.Component { + render() { + return
; + } +} + +export default CDepth7Nested2; diff --git a/test/traverse-nested.spec.tsx b/test/traverse-nested.spec.tsx index 815e181..cbc9816 100644 --- a/test/traverse-nested.spec.tsx +++ b/test/traverse-nested.spec.tsx @@ -7,6 +7,7 @@ import { traverse } from "../src"; import { mountAndGetRootNode } from "./utils/mount-in-enzyme"; import CDepth2Nested1 from "./sample-components/depth-2-nested-1"; import CDepth3Nested1 from "./sample-components/depth-3-nested-1"; +import CDepth7Nested2 from "./sample-components/depth-7-nested-2"; describe("traverse", () => { let container: HTMLDivElement; @@ -28,16 +29,25 @@ describe("traverse", () => { expect(mockCallback.mock.calls.length).toBe(2); }); - }); - it("should work for depth=3 with level of nesting=1", () => { - const rootNode = mountAndGetRootNode(CDepth3Nested1, container); - const mockCallback = jest.fn(); + it("should work for depth=3 with level of nesting=1", () => { + const rootNode = mountAndGetRootNode(CDepth3Nested1, container); + const mockCallback = jest.fn(); - traverse(rootNode, mockCallback); + traverse(rootNode, mockCallback); - // Shouldn't count just component depth, should include string nodes - expect(mockCallback.mock.calls.length).not.toBe(2); - expect(mockCallback.mock.calls.length).toBe(3); + // Shouldn't count just component depth, should include string nodes + expect(mockCallback.mock.calls.length).not.toBe(2); + expect(mockCallback.mock.calls.length).toBe(3); + }); + + it("should work for depth=7 with level of nesting=2", () => { + const rootNode = mountAndGetRootNode(CDepth7Nested2, container); + const mockCallback = jest.fn(); + + traverse(rootNode, mockCallback); + + expect(mockCallback.mock.calls.length).toBe(7); + }); }); });