Skip to content

Entire error output to console during a .toThrow() assertion #157

Closed
@good-idea

Description

@good-idea
  • react-testing-library version: 5.0.0
  • react version: 16.4.2
  • node version: 8.11.3
  • npm (or yarn) version: yarn 1.9.4

Relevant code or config:

const Component = props => {
	if (props.throw) throw new Error('!!')
	return <div>😀</div>
}
it('Throws an error when `props.throw === true`', () => {
	const renderComponent = () => render(<Component throw />)
	expect(renderComponent).toThrow('!!')
})

What you did:

I'm making a jest assertion that a component will throw an error under certain circumstances.

What happened:

While the test itself passes, the entire error shows up in the Jest output. Under other circumstances, jest suppresses errors that are thrown within a .toThrow() assertion. (there's a test in the repo that shows this)

Reproduction:

https://github.com/good-idea/rtl-throws-error

Problem description:

Lots of unnecessary console output!

Suggested solution:

I haven't looked into how jest / RTL handles all of this and how it might be happening, but I'm happy to put together a PR. Just point me in the right direction!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions