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.

Source code

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)

最新文章

  1. web常见错误提示总结
  2. [.net 面向对象程序设计深入](2)UML——在Visual Studio 2013/2015中设计UML用例图
  3. Difference Between HashMap and IdentityHashMap--转
  4. POJ 3061 (二分+前缀和or尺取法)
  5. CentOS 7数据库mysql和mariadb手动安装冲突的问题解决
  6. windows上在linux客户端上传小文件lrzsz
  7. hduoj------2594 Simpsons’ Hidden Talents
  8. [iOS微博项目 - 3.0] - 手动刷新微博
  9. poj 3278 Catch That Cow 优化深搜
  10. nginx配置记录
  11. Effective Java 第三版——9. 使用try-with-resources语句替代try-finally语句
  12. Cannot change version of project facet Dynamic Web Module to 2.5的解决
  13. Android初级教程:如何自定义一个状态选择器
  14. vue 常用语法糖
  15. 用js检测文本框中输入的是否符合条件并有错误和正确提醒
  16. day 13
  17. pgm16
  18. PTA 7-2 二叉搜索树的结构(30 分)
  19. java HttpServletRequest和HttpServletResponse詳解
  20. 浅浅的分析LED呼吸灯的实现和PWM的关系

热门文章

  1. RequireJS 上手使用
  2. linux远程开机
  3. windows远程桌面链接“发生身份验证错误。要求的函数不受支持”
  4. django 标签
  5. C#语言中循环分类总结
  6. 导航栏 active 跟随鼠标效果
  7. 笔试算法题(08):输出倒数第K个节点
  8. <Redis> 入门二 五种数据类型的操作、通用key的操作、发布订阅
  9. Django, one-to-many, many-to-many
  10. 转载,Django组件