-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.mdx
48 lines (36 loc) · 1.08 KB
/
index.mdx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
---
title: Enzyme Stuff
shortDescription:
Miscellaneous snippets for working if you have to do tests with Enzyme
category: react
tags:
- javascript
- typescript
- testing
- enzyme
createdAt: '2022-02-20'
updatedAt: '2022-11-30'
---
## Input Change Event
Simulate the `change` event on an `<input />`
```jsx
const wrapper = shallow(<ComponentThatRendersAnInput />)
const inputWrapper = wrapper.find('input[type="email"]')
// Change `target` to `currentTarget` if you're updating state based on that instead
inputWrapper.simulate('change', {
target: { value: 'soorria.ss@gmail.com' },
})
```
## Form Submit Event
Simulate the `submit` event on a `<form />`.
```jsx
const noop = () => {}
const wrapper = shallow(<ComponentThatRendersAForm />)
const formWrapper = wrapper.find('form')
formWrapper.simulate('submit', { preventDefault: noop })
```
<Note variant="warning">
- Unfortunately this does not work properly if you're using `FormData` 😔
- You can't test submitting a form by clicking a button / input with
`type="submit"` due to events not working the same in jsdom
</Note>