码迷,mamicode.com
首页 > 其他好文 > 详细

[React Testing] Improve Test Confidence with the User Event Module

时间:2020-04-30 19:32:54      阅读:70      评论:0      收藏:0      [点我收藏+]

标签:rac   ESS   expec   render   ror   tools   testing   nts   library   

The User Event module is part of the Testing Library family of tools and lets you fire events on DOM nodes that more closely resemble the way your users will interact with your elements. Let’s refactor our fire event usages to use that instead.

 

import user from @testing-library/user-event

test(v2: entering an invalid value shows an error message, () => {
  const { getByLabelText, getByRole } = render(<FavoriteNumber />)
  const input = getByLabelText(/favorite number/i)
  // simulate a user type on input
  user.type(input, ‘10‘)
  expect(getByRole(alert)).toHaveTextContent(/the number is invalid/i)
})

 

[React Testing] Improve Test Confidence with the User Event Module

标签:rac   ESS   expec   render   ror   tools   testing   nts   library   

原文地址:https://www.cnblogs.com/Answer1215/p/12810682.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!