我正在使用mocha,酶来创建反应组分的单元测试.下面是一个示例组件.
Foo.js
class Foo extends React.Component {
customFunction=() => {
}
render() {
return (<div className={this.props.name}/>);
}
}
Run Code Online (Sandbox Code Playgroud)
这是测试文件.
富-Test.js
import React from 'react';
import { expect } from 'chai';
import { shallow, mount, render } from 'enzyme';
import Foo from '../src/Foo';
describe("A suite", function() {
it("contains spec with an expectation", function() {
expect(shallow(<Foo />).contains(<div className="foo" />)).to.equal(true);
});
it("contains spec with an expectation", function() {
expect(shallow(<Foo />).is('.foo')).to.equal(true);
});
});
Run Code Online (Sandbox Code Playgroud)
一切都是好的.但是当我们使用酶时,我不明白如何在Foo.js中对customFunction进行单元测试