From 36755eee137013d20fce47e645821b22afd6bd33 Mon Sep 17 00:00:00 2001 From: mikieyx <103902194+mikieyx@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:04:05 -0700 Subject: [PATCH] #2006 Use React Testing Library for icons tests (#2002) Signed-off-by: Michael Pavlik --- .../__tests__/icons/icon-test.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/canvas_modules/common-canvas/__tests__/icons/icon-test.js b/canvas_modules/common-canvas/__tests__/icons/icon-test.js index 8706843135..efb4a37f27 100644 --- a/canvas_modules/common-canvas/__tests__/icons/icon-test.js +++ b/canvas_modules/common-canvas/__tests__/icons/icon-test.js @@ -15,7 +15,7 @@ */ import React from "react"; -import { mount, shallow } from "enzyme"; +import { render } from "@testing-library/react"; import Icon from "../../src/icons/icon.jsx"; import { expect } from "chai"; @@ -23,23 +23,23 @@ import { expect } from "chai"; describe("Icon renders correctly", () => { it("should render a div when type unknown", () => { - const icon = shallow(); - expect(icon.find("div")).to.have.length(1); + const icon = render(); + // divs have generic roles, thus when icon is set to unknown, there is supposed to be 2 elements with generic roles + expect(icon.getAllByRole("generic")).to.have.length(2); }); it("should render a svg when type known", () => { - const icon = mount(); - - expect(icon.find("svg")).to.have.length(1); + const { container } = render(); + expect(container.getElementsByClassName("canvas-icon")).to.have.length(1); }); it("should render a svg with class name", () => { - const icon = mount(); - expect(icon.find("svg.svg-test-class")).to.have.length(1); + const { container } = render(); + expect(container.getElementsByClassName("svg-test-class")).to.have.length(1); }); it("should render a svg with class 'properties-icon'", () => { - const icon = mount(); - expect(icon.find("svg.properties-icon")).to.have.length(1); + const { container } = render(); + expect(container.getElementsByClassName("properties-icon")).to.have.length(1); }); });