enzyme

How to test styled components conditionally and children elements?

…衆ロ難τιáo~ 提交于 2020-08-25 03:52:15
问题 I'm new to unit testing and I've spent some 20-30 hours in docs, articles and YT videos but still can't make sense of how to achieve this. Basically I want to test 3 things here: Make sure that this component renders 3 components Test the conditional styling Test the click event So far, for the 1st thing, if I try to do: import { shallow } from "enzyme"; import React from "react"; import ButtonsComponent, { SchedButton } from "./ButtonsComponent"; it("renders three <MyButton /> components", (

How to test styled components conditionally and children elements?

浪子不回头ぞ 提交于 2020-08-25 03:52:05
问题 I'm new to unit testing and I've spent some 20-30 hours in docs, articles and YT videos but still can't make sense of how to achieve this. Basically I want to test 3 things here: Make sure that this component renders 3 components Test the conditional styling Test the click event So far, for the 1st thing, if I try to do: import { shallow } from "enzyme"; import React from "react"; import ButtonsComponent, { SchedButton } from "./ButtonsComponent"; it("renders three <MyButton /> components", (

How do you simulate an keyDown enter event (or others) in Enzyme?

我只是一个虾纸丫 提交于 2020-08-21 04:57:47
问题 I'm trying to simulate a keyDown event, specifically for Enter, keyCode: 13 . I've tried a number of different ways of doing this, but none of them are working. I've also looked online and it seems like this feature is either buggy or not working in the current version of Enzyme. Does anyone know definitively if this feature works, and if so, what is the proper syntax for simulating an enter, or other types of key events? Thanks! This is what I have currently, and it's not working: const

敬请指正-我进行单元测试的分享

泪湿孤枕 提交于 2020-08-10 04:35:12
单元测试的好处是啥? 重构、重构、重构,重要的事情说三遍 TDD(测试驱动开发)的具体实现就是通过红灯->绿灯->重构不断重复,一步一步去健壮我们的代码,保证今后重构代码的时候测试的准确,可以在重构中准确的定位到问题。同时也为以后的开发提供支持,在测试的基础上我们可以重构结构和业务功能。 单元测试是最好的注释 测试会提示你哪些步骤是可以通过、如何使用的最好文档。更详细的规范了测试目标的边界值与非法值。 定位bug,减少bug 单元测试可以通过不同的条件来发现问题在哪里,在一些弱类型的语言中也避免了一些类型检查的低级错误,当然这个现在我们都用TypeScript做到了。 被迫的规范组织结构 可能平时我们会把一个方法写的很复杂、一个类写的很大,没有想过如何去组织结构,但如果你想到你即将的测试要如何写的时候,那可能你在开发前必须要想想哪些部分可以提出来了。这样会慢慢养成很好的思维。 好了,不多BB,看看怎么用吧!!! 我用的是jest测试哦!!! 1.看一下我的jest.config.js中 testMatch ,告诉我需要在lib文件夹中创建个目录 __tests__ , __tests__ 的目录里面 xxxx.unit.(js|jsx|ts|tsx) 这样的文件就是测试文件 加入我们642830685,领取最新软件测试大厂面试资料和Python自动化、接口、框架搭建学习资料!

敬请指正-我进行单元测试的分享

百般思念 提交于 2020-08-07 01:13:32
单元测试的好处是啥? 重构、重构、重构,重要的事情说三遍 TDD(测试驱动开发)的具体实现就是通过红灯->绿灯->重构不断重复,一步一步去健壮我们的代码,保证今后重构代码的时候测试的准确,可以在重构中准确的定位到问题。同时也为以后的开发提供支持,在测试的基础上我们可以重构结构和业务功能。 单元测试是最好的注释 测试会提示你哪些步骤是可以通过、如何使用的最好文档。更详细的规范了测试目标的边界值与非法值。 定位bug,减少bug 单元测试可以通过不同的条件来发现问题在哪里,在一些弱类型的语言中也避免了一些类型检查的低级错误,当然这个现在我们都用TypeScript做到了。 被迫的规范组织结构 可能平时我们会把一个方法写的很复杂、一个类写的很大,没有想过如何去组织结构,但如果你想到你即将的测试要如何写的时候,那可能你在开发前必须要想想哪些部分可以提出来了。这样会慢慢养成很好的思维。 好了,不多BB,看看怎么用吧!!! 我用的是jest测试哦!!! 1.看一下我的jest.config.js中 testMatch ,告诉我需要在lib文件夹中创建个目录 __tests__ , __tests__ 的目录里面 xxxx.unit.(js|jsx|ts|tsx) 这样的文件就是测试文件 加入我们642830685,领取最新软件测试大厂面试资料和Python自动化、接口、框架搭建学习资料!

为 React 开发人员推荐 8 个测试工具、库和框架

时光总嘲笑我的痴心妄想 提交于 2020-07-29 00:54:12
云栖号资讯:【 点击查看更多行业资讯 】 在这里您可以找到不同行业的第一手的上云资讯,还在等什么,快来! 很多开发人员都很喜欢 React,在前端领域它也是很流行的 UI 库了。我们也知道应用要交付生产环境前是必须要经过完善的测试的,而测试应用程序时,有趁手的工具能极大减轻开发人员的负担、提升测试效率并减少测试漏洞。正所谓"工欲善其事,必先利其器",这篇文章就为大家推荐 8 个好用的测试工具、库和框架。本文编译自 GeeksforGeeks 网站。 如果你是前端工程师,日常工作中经常会用到 React 库,那么你手里可能已经有一些用来测试 React 应用的工具或框架了。许多开发人员会使用 Jest、Enzyme 或其他一些流行的工具和库来测试 React 应用组件。但毕竟萝卜青菜各有所爱,开源生态系统中又有大量用于 React 应用的测试框架和工具,所以很多人(尤其是新人)很容易在这个问题上犯选择困难症。下面我们会介绍一些流行好用的 React 测试框架和库,供大家参考。 1.Jest Jest 是最受欢迎的测试框架,每周下载超过 1600 万次。它是由 Facebook 创建和维护的。FB 团队用它来测试所有 JavaScript 代码,也包括 React 应用程序。Airbnb、Uber、Intuit 等公司的团队也在用它。Jest 附带了测试运行器和断言功能。就算是刚刚接触

提问回顾与个人总结

无人久伴 提交于 2020-07-24 22:24:49
这是一个填坑博客,负责把之前 挖坑博客 里面所挖的坑填满,以及一个学习软件工程课的心得。 项目 内容 课程:北航2020春软件工程 博客园班级博客 作业:提问回顾与个人总结 提问回顾与个人总结 提问博客 软工个人博客作业1 疑问解答 问题一:测试 在之前的面向对象设计的课程中,我初步地尝试了使用JUnit对自己的单元进行测试。但是对于测试的对象、粒度和测试的样例数据,我还是不能很好的把握。测试的粒度可以从小到大,从函数、方法到类再到模块,循序渐进。但是测试的样例数据方面,是否存在比较合理而且固定的方法,能够固定地按照一个流程去分析自己的应用,做到不重不漏,覆盖到所有的分支和情况?还是说单纯依靠代码的编写者去“我 觉得 ,这个地方 可能 存在问题”这样的直觉和经验呢? 覆盖所有分支肯定是不太可能的,每个模块的输入和输出变化非常大,这也是为什么说“测试需要写代码的人做”的原因。但是其中我们当然可以使用一些工具比如分支覆盖率工具,在给定输入的情况下检查代码的覆盖率。在结对编程和团队工作的过程中,我的测试方法主要分为两种: 人工制造数据,分别检测“一般情况”和“边界情况”,并同时利用分支覆盖率工具来检查代码的正确性 通过随机生成函数,批量制造随机输入数据和对应的期望输出,然后挂机让电脑自己测试 问题二:结对分配 过程中,我想知道结对编程过程中,是否会发生两者的贡献不匹配的情况。作为领航员

Encountered an nuexpected token - Jjest redux-saga core

你。 提交于 2020-07-10 06:46:12
问题 I have gotten this error on different tests with Jest after some updates of React, and other npm packages, and after I have used a new npm module. I think the problem this time is laying inside the MyApp\node_modules\@redux-saga\core\dist\redux-saga-core.dev.cjs.js:734 . Here is my error, where I have swapped my real project name with MyApp : 2 ● 2Test suite failed to run 2 2 ;31Jest encountered an unexpected token This usually means that you are trying to import a file which Jest cannot

How can Enzyme check for component visibility?

血红的双手。 提交于 2020-06-29 03:51:56
问题 I've attached a cut down version of an issue I am having. I have a simple Checkbox which I hide using opacity : 0 depending on what is passed into the component containing the Checkbox (in this case MyCheckbox ) MyCheckBox.js import React from "react"; import "./styles.css"; import { Checkbox, makeStyles } from "@material-ui/core"; const useStyles = makeStyles({ checkboxHiddenStyle: { opacity: 0 } }); export default function MyCheckbox(props) { const styles = useStyles(props); return ( <div>

How to test FileReader onload using simulate change in jest?

跟風遠走 提交于 2020-06-28 07:07:10
问题 SimpleDialog.jsx const [imagePreview, setImagePreview] = React.useState(null); const handleChangeImage = event => { let reader = new FileReader(); let file = event.target.files[0]; reader.onload = event => { console.log(event); setImagePreview(event.target.result); }; reader.readAsDataURL(file); }; return ( <div> <input accept="image/*" id="contained-button-file" multiple type="file" style={{ display: 'none' }} onChange={handleChangeImage} /> <img id="preview" src={imagePreview} /> </div> );