react-testing-library

how to test react-select with react-testing-library

蓝咒 提交于 2019-12-01 02:45:17
问题 App.js import React, { Component } from "react"; import Select from "react-select"; const SELECT_OPTIONS = ["FOO", "BAR"].map(e => { return { value: e, label: e }; }); class App extends Component { state = { selected: SELECT_OPTIONS[0].value }; handleSelectChange = e => { this.setState({ selected: e.value }); }; render() { const { selected } = this.state; const value = { value: selected, label: selected }; return ( <div className="App"> <div data-testid="select"> <Select multi={false} value=

How to test a className with Jest and React testing library

一世执手 提交于 2019-11-28 03:01:12
问题 I am totally new to JavaScript testing and working in a new codebase. I would like to write a test that is checking for a className on the element. I am working with Jest and react-testing-library. Below I have a test that will render a button based on the variant prop. It also contains a className and .I would like to test that. it('Renders with a className equal to the variant', () => { const { container } = render(<Button variant="default" />) expect(container.firstChild) // Check for