[Jest] Automate your migration to Jest using codemods
Jest is a fantastic testing library, but maybe you've been putting off the switch because migrating all of your existing tests from another library seems like a daunting task. With jest-codemods, you can automate most, if not all, of that migration! The jest-codemods CLI is a wrapper around jscodeshift that is specifically focused on helping you migrate from several popular test runner and assertion library combinations to Jest. In this lesson, we'll walk through converting a small sampling of tests created with Mocha, Sinon and Chai over to Jest. We'll even take a look at a couple edge cases where the conversion requires some manual intervention so you can be prepared for those in your own project.
Install:
npm i -D jest npm i -g jest-codemons
Run:
jest-codemods # default path is under src
There is a waring:
"
jest-codemods warning: (src/index.spec.js) Usage of package "sinon" might be incompatible with Jest
"
describe('once', () => {
test('Only invokes the function once', () => {
const fn = sinon.stub()
const onceFn = once(fn)
onceFn()
onceFn()
onceFn()
onceFn()
sinon.assert.calledOnce(fn)
})
})
Change to:
describe('once', () => {
test('Only invokes the function once', () => {
const fn = jest.fn();
const onceFn = once(fn)
onceFn()
onceFn()
onceFn()
onceFn()
expect(fn).toHaveBeenCalledTimes(1);
})
})
One failed test:
expect(result).to.eq(3)
Change to:
expect(result).toBe(3)
最新文章
- web常见错误提示总结
- [.net 面向对象程序设计深入](2)UML——在Visual Studio 2013/2015中设计UML用例图
- Difference Between HashMap and IdentityHashMap--转
- POJ 3061 (二分+前缀和or尺取法)
- CentOS 7数据库mysql和mariadb手动安装冲突的问题解决
- windows上在linux客户端上传小文件lrzsz
- hduoj------2594 Simpsons’ Hidden Talents
- [iOS微博项目 - 3.0] - 手动刷新微博
- poj 3278 Catch That Cow 优化深搜
- nginx配置记录
- Effective Java 第三版——9. 使用try-with-resources语句替代try-finally语句
- Cannot change version of project facet Dynamic Web Module to 2.5的解决
- Android初级教程:如何自定义一个状态选择器
- vue 常用语法糖
- 用js检测文本框中输入的是否符合条件并有错误和正确提醒
- day 13
- pgm16
- PTA 7-2 二叉搜索树的结构(30 分)
- java HttpServletRequest和HttpServletResponse詳解
- 浅浅的分析LED呼吸灯的实现和PWM的关系