From a463b3ba86786f5f36d465ac7f4ff3bf5ebe8066 Mon Sep 17 00:00:00 2001 From: Rachel Dauns Date: Mon, 15 Apr 2024 09:16:32 -0400 Subject: [PATCH] switch test enzyme removed --- .../__tests__/common/components/switch.test.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/app/obojobo-document-engine/__tests__/common/components/switch.test.js b/packages/app/obojobo-document-engine/__tests__/common/components/switch.test.js index e2826decae..70ece6882d 100644 --- a/packages/app/obojobo-document-engine/__tests__/common/components/switch.test.js +++ b/packages/app/obojobo-document-engine/__tests__/common/components/switch.test.js @@ -1,7 +1,6 @@ import React from 'react' import Switch from '../../../src/scripts/common/components/switch' import TestRenderer from 'react-test-renderer' -import { mount } from 'enzyme' describe('Switch', () => { test('Switch renders correctly with no options set', () => { @@ -41,11 +40,19 @@ describe('Switch', () => { test('Switch calls onChange', () => { const onChecked = jest.fn() - const component = mount() - const checkbox = component.find('input') + const component = TestRenderer.create() + const checkbox = component.root.findByType('input') + + // Initially, the onChange function should not have been called expect(onChecked).not.toHaveBeenCalled() - checkbox.simulate('change', { target: { checked: true } }) + + // Simulate the change event by directly setting the checked attribute of the input element + checkbox.props.onChange({ target: { checked: true } }) + + // After simulating the change event, the onChange function should have been called once expect(onChecked).toHaveBeenCalledTimes(1) + + // Also, it should have been called with the expected argument expect(onChecked).toHaveBeenCalledWith(expect.objectContaining({ target: { checked: true } })) }) })