Unit Test (Jest & enzyme)
Enzyme
shallow, render, mount 差異
import React from 'react';
import { shallow, configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import test from '../index';
configure({ adapter: new Adapter() });
describe('<test />', () => {
it('should render and match the snapshot', () => {
const wrapper = shallow(<test />);
expect(wrapper).toMatchSnapshot();
});
});Jest
也可用react-test-renderer
Test coverage
測試單一檔案
測試Function
測試 Component Function
測試Module
取得 props
測component 不在 class 內的 function
如果React children component 內的沒cover到
點擊測試
測試component 內 children的 prop
測試 defaultProp
Find 元素
設定 window 相關變數
Hook UseEffect
Last updated