From b0fe06bc2e739cc252a559f666da65b27769959d Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Wed, 15 Apr 2020 19:35:15 +0900 Subject: Fix types in tests --- .../console/components/console/Completion.test.tsx | 50 +++++++++++++--------- 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'test/console/components') diff --git a/test/console/components/console/Completion.test.tsx b/test/console/components/console/Completion.test.tsx index 200bb1a..921720b 100644 --- a/test/console/components/console/Completion.test.tsx +++ b/test/console/components/console/Completion.test.tsx @@ -1,6 +1,9 @@ import React from "react"; -import Completion from "console/components/console/Completion"; -import ReactTestRenderer from "react-test-renderer"; +import Completion from "../../../../src/console/components/console/Completion"; +import ReactTestRenderer, { ReactTestInstance } from "react-test-renderer"; +import { expect } from "chai"; +import CompletionTitle from "../../../../src/console/components/console/CompletionTitle"; +import CompletionItem from "../../../../src/console/components/console/CompletionItem"; describe("console/components/console/completion", () => { const completions = [ @@ -24,13 +27,22 @@ describe("console/components/console/completion", () => { it("renders Completion component", () => { const root = ReactTestRenderer.create( - + ).root; - expect(root.children).to.have.lengthOf(1); - - const children = root.children[0].children; + // const children = root.findByType('ul').children as Array; + const children = root.findByType("ul").children as Array; expect(children).to.have.lengthOf(8); + expect(children.map((e) => e.type)).to.deep.equal([ + CompletionTitle, + CompletionItem, + CompletionItem, + CompletionItem, + CompletionTitle, + CompletionItem, + CompletionItem, + CompletionItem, + ]); expect(children[0].props.title).to.equal("Fruit"); expect(children[1].props.caption).to.equal("apple"); expect(children[2].props.caption).to.equal("banana"); @@ -46,7 +58,7 @@ describe("console/components/console/completion", () => { ).root; - const children = root.children[0].children; + const children = root.findByType("ul").children as Array; expect(children[5].props.highlight).to.be.true; }); @@ -55,10 +67,8 @@ describe("console/components/console/completion", () => { ).root; - const children = root.children[0].children; - for (const li of children[0].children) { - expect(li.props.highlight).not.to.be.ok; - } + const children = root.findByType("ul").findAllByType(CompletionItem); + expect(children.every((e) => e.props.highlight === false)).to.be.true; }); it("limits completion items", () => { @@ -66,7 +76,7 @@ describe("console/components/console/completion", () => { ).root; - let children = root.children[0].children; + let children = root.findByType("ul").children as Array; expect(children).to.have.lengthOf(3); expect(children[0].props.title).to.equal("Fruit"); @@ -77,7 +87,7 @@ describe("console/components/console/completion", () => { ).root; - children = root.children[0].children; + children = root.findByType("ul").children as Array; expect(children[1].props.highlight).to.be.true; }); @@ -87,7 +97,7 @@ describe("console/components/console/completion", () => { ); const root = component.root; - let children = root.children[0].children; + let children = root.findByType("ul").children as Array; expect(children).to.have.lengthOf(3); expect(children[0].props.title).to.equal("Fruit"); expect(children[1].props.caption).to.equal("apple"); @@ -97,7 +107,7 @@ describe("console/components/console/completion", () => { ); - children = root.children[0].children; + children = root.findByType("ul").children as Array; expect(children).to.have.lengthOf(3); expect(children[0].props.caption).to.equal("apple"); expect(children[1].props.caption).to.equal("banana"); @@ -108,7 +118,7 @@ describe("console/components/console/completion", () => { ); - children = root.children[0].children; + children = root.findByType("ul").children as Array; expect(children).to.have.lengthOf(3); expect(children[0].props.caption).to.equal("cherry"); expect(children[1].props.title).to.equal("Element"); @@ -122,7 +132,7 @@ describe("console/components/console/completion", () => { ); const root = component.root; - let children = root.children[0].children; + let children = root.findByType("ul").children as Array; expect(children).to.have.lengthOf(3); expect(children[0].props.caption).to.equal("argon"); expect(children[1].props.caption).to.equal("boron"); @@ -132,21 +142,21 @@ describe("console/components/console/completion", () => { ); - children = root.children[0].children; + children = root.findByType("ul").children as Array; expect(children[1].props.highlight).to.be.true; component.update( ); - children = root.children[0].children; + children = root.findByType("ul").children as Array; expect(children[0].props.highlight).to.be.true; component.update( ); - children = root.children[0].children; + children = root.findByType("ul").children as Array; expect(children[0].props.caption).to.equal("cherry"); expect(children[1].props.title).to.equal("Element"); expect(children[2].props.caption).to.equal("argon"); -- cgit v1.2.3