huixisheng / huixisheng.github.com

前端开发者说,记录前端的故事
http://huixisheng.github.io/
12 stars 3 forks source link

前端单元测试 #80

Open huixisheng opened 5 years ago

huixisheng commented 5 years ago

最近在阅读 Vue 的源码,对项目中用到单元测试的知识点做个学习笔记

jasminekarmaChromeHeadless

  plugins: [
    'karma-jasmine',
    'karma-mocha-reporter',
    'karma-sourcemap-loader',
    'karma-webpack'
  ]
    plugins: base.plugins.concat([
      'karma-chrome-launcher'
    ])
huixisheng commented 3 years ago
// setupTests.ts
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
import { render, cleanup, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';
huixisheng commented 3 years ago

官网推荐文档

huixisheng commented 3 years ago

综合资源

huixisheng commented 3 years ago
huixisheng commented 3 years ago

碰到问题

ts 的后缀改成 tsx

image

huixisheng commented 3 years ago

Enzyme + jest