-
-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Errors when using simulate() api #45
Comments
This is currently a difference from the React Enzyme adapters which, AFAIK, don't actually dispatch a real event. Does this answer your question? |
Well yes, thanks for your time and for the explanation. Maybe it could be worth to add a gotcha on the readme cause the official enzyme documentation suggest another way to handle events. |
I have added some notes about differences between Enzyme + React and Enzyme + Preact in the README which covers this. I think in future it may make sense to change the behaviour to match the React adapters, but that would be a breaking change so I have simply documented it for now. |
I had the same problem. What should I do when I test functional component like this? export default function Login() {
const [ form, setForm ] = useState({ email: '' })
return (
<form>
<input value={form.email} placeholder="Email" onInput={e => setForm({ email: e.currentTarget.value })}>
<button disabled={!form.email}>Login</button>
</form>
)
} it('should set button enabled when form is valid', function () {
const wrapper = shallow(<Login />)
wrapper.find('[placeholder="Email"]').simulate('input', { currentTarget: { value: '123' } })
const loginButton = wrapper.find('form button.btn-lg.btn-primary')
expect(loginButton.props().disabled).toBe(false)
}) I can't change the internal state if I can't simulate event. Is there anything wrong with me? @robertknight @ingro |
I might add, when I try to use wrapper.find('[placeholder="Email"]').getDOMNode<HTMLInputElement>().value = '123' I got an error |
@mutoe - You can't get a reference to the DOM node if you use At work, we combine the advantages of |
@robertknight Thanks for your answer, By the way, can |
@robertknight I made a small patch which provides an opportunity to pass |
Hello! I'm trying to test the behaviour of a checkbox component.
But calling the
simulate
api causes me multiple problems.First I had this error:
which I resolved by putting Event in the global namespace in my setup file:
But then I got another error:
If I pass as arg a random key the error is not thrown but of course the test fail:
For reference I'm using latest Preact (v10.0.0-beta.1) and latest enzyme-adapter-preact-pure (v1.13.1).
The text was updated successfully, but these errors were encountered: