Skip to content

Commit

Permalink
text-menu enzyme removed
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelDau committed Apr 16, 2024
1 parent a463b3b commit b5fba46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,12 @@ describe('Switch', () => {
const component = TestRenderer.create(<Switch onChange={onChecked} />)
const checkbox = component.root.findByType('input')

// Initially, the onChange function should not have been called
expect(onChecked).not.toHaveBeenCalled()

// 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 } }))
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react'
import renderer from 'react-test-renderer'
import { mount } from 'enzyme'

import TextMenu from '../../../src/scripts/common/components/text-menu'

const createRect = () => {
Expand Down Expand Up @@ -59,8 +57,12 @@ describe('TextMenu', () => {

test('TextMenu calls mouseDown', () => {
const mockCommandHandler = jest.fn()
const mockEvent = {
preventDefault: jest.fn(),
stopPropagation: jest.fn()
}

const component = mount(
const component = renderer.create(
<TextMenu
relativeToElement={{
getBoundingClientRect: () => createRect()
Expand All @@ -72,8 +74,12 @@ describe('TextMenu', () => {
/>
)

component.find('a').simulate('mouseDown')
const linkElement = component.root.findByType('a')

linkElement.props.onMouseDown(mockEvent, 'Label')

expect(mockEvent.preventDefault).toHaveBeenCalledTimes(1)
expect(mockEvent.stopPropagation).toHaveBeenCalledTimes(1)
expect(mockCommandHandler).toHaveBeenCalledWith('Label')
})
})

0 comments on commit b5fba46

Please sign in to comment.