Hi there,
I want to write unit tests for my react components in typescript. I am using (EF) Element Framework. React 18 and @testing-library/react. Basically, the default set up for create-react app.
I can only test functions. I cannot test any of the functionality of the EF components.
e.g. the debug methods show this for the toggle component
<body>
<ef-tooltip
ref="title-override"
/>
<div>
<ef-toggle />
</div>
</body>
- How can I select elements?
const { container } = render(<CurrencyPairToggle value={value} callback={setState} />)
const toggle = container.querySelector('ef-toggle')
debug()
This code works, but I do not think this is the right way of doing this.
Normal search variants do not work. E.g. queryByText, queryByRole
- Can I even trigger an event for the components. E.g fireEvent.click for a toggle?
- At least how can I test if the label or the checkedLabel are populated with the right value?
- E.g. expect(screen.getByRole("switch")).toHaveAttribute("label", "USD")
- Note: toggle uses the role ‘switch’
Many thanks for your help