我正在使用react-testing-library
对React组件进行单元测试。
import React from 'react'
import 'react-testing-library/cleanup-after-each'
import {fireEvent, render, cleanup} from 'react-testing-library'
import MyComponent from '../MyComponent';
const translations = require('../../translations');
afterEach(cleanup);
describe('test MyComponent', () => {
it('render functional component', () => {
// extract container which is 'HTMLDivElement'
const {container} = render(<MyComponent translations={translations} />)
})
如何将容器元素作为DOM元素处理?例如。
console.log(container.classList, container.id, container.innerHTML);
使用https://developer.mozilla.org/en-US/docs/Web/API/Element中列出的道具和方法。到目前为止,我还没有任何值。