From 1b6f814de7a026be61a3514a979ac97fb3ced533 Mon Sep 17 00:00:00 2001 From: Rachel Dauns Date: Wed, 10 Apr 2024 12:56:34 -0400 Subject: [PATCH] enzyme removed from button-bar and delete-buton-base --- .../common/components/button-bar.test.js | 31 +++++++------------ .../components/delete-button-base.test.js | 9 +++--- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/packages/app/obojobo-document-engine/__tests__/common/components/button-bar.test.js b/packages/app/obojobo-document-engine/__tests__/common/components/button-bar.test.js index e7fea9c6ba..175ceaa597 100644 --- a/packages/app/obojobo-document-engine/__tests__/common/components/button-bar.test.js +++ b/packages/app/obojobo-document-engine/__tests__/common/components/button-bar.test.js @@ -1,7 +1,6 @@ import React from 'react' import ButtonBar from '../../../src/scripts/common/components/button-bar' import renderer from 'react-test-renderer' -import { mount } from 'enzyme' describe('ButtonBar', () => { test('ButtonBar component', () => { @@ -35,21 +34,18 @@ describe('ButtonBar', () => { } ] const mockClick = jest.fn() - const component = mount({children}) + const component = renderer.create({children}) + const buttonInstance = component.root.findByType('button') - component - .childAt(0) - .find('button') - .simulate('click') - expect(mockClick).toBeCalledTimes(1) + buttonInstance.props.onClick() + expect(mockClick).toHaveBeenCalledTimes(1) // default function coverage for buttonBarOnClick - const componentNoClick = mount({children}) - componentNoClick - .childAt(0) - .find('button') - .simulate('click') - expect(mockClick).toBeCalledTimes(1) + const componentNoClick = renderer.create({children}) + const buttonInstanceNoClick = componentNoClick.root.findByType('button') + + buttonInstanceNoClick.props.onClick() + expect(mockClick).toHaveBeenCalledTimes(1) }) test('ButtonBar component clicks button but does not fire', () => { @@ -59,13 +55,10 @@ describe('ButtonBar', () => { } ] const mockClick = jest.fn() - const component = mount({children}) - - component - .childAt(0) - .find('button') - .simulate('click') + const component = renderer.create({children}) + const buttonInstance = component.root.findByType('button') + buttonInstance.props.onClick() expect(mockClick).toHaveBeenCalled() }) }) diff --git a/packages/app/obojobo-document-engine/__tests__/common/components/delete-button-base.test.js b/packages/app/obojobo-document-engine/__tests__/common/components/delete-button-base.test.js index 125b662712..6daf333fa3 100644 --- a/packages/app/obojobo-document-engine/__tests__/common/components/delete-button-base.test.js +++ b/packages/app/obojobo-document-engine/__tests__/common/components/delete-button-base.test.js @@ -1,7 +1,6 @@ import React from 'react' import DeleteButton from '../../../src/scripts/common/components/delete-button' import DeleteButtonBase from '../../../src/scripts/common/components/delete-button-base' -import { mount } from 'enzyme' import renderer from 'react-test-renderer' jest.mock('../../../src/scripts/common/page/focus') @@ -44,9 +43,9 @@ describe('DeleteButton', () => { test('DeleteButton calls focus callback with ref argument', () => { const focus = require('../../../src/scripts/common/page/focus').default - const wrapper = mount() - const inst = wrapper.find(DeleteButtonBase).instance() - inst.focus() - expect(focus).toHaveBeenCalledWith(inst.deleteButtonRef) + const component = renderer.create() + const inst = component.root.findByType(DeleteButtonBase).instance // Get the instance of DeleteButton + inst.focus() // Call the focus method + expect(focus).toHaveBeenCalledWith(inst.deleteButtonRef) // Check if focus callback is called with correct argument }) })