zoukankan      html  css  js  c++  java
  • [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.

    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)
  • 相关阅读:
    EPUB书籍阅读器插件分享
    网页端压缩解压缩插件JSZIP库的使用
    让编辑器支持word的复制黏贴,支持截屏的黏贴
    MYSQL GTID position
    Google SRE
    MySQL大小写敏感
    SpringMVC model 多余字段 忽略
    To B Vs To C
    滴滴 CTO 架构师 业务 技术 战役 时间 赛跑 超前 设计
    Spring Boot 集成Swagger
  • 原文地址:https://www.cnblogs.com/Answer1215/p/9515376.html
Copyright © 2011-2022 走看看