小编pns*_*ddy的帖子

Mocha,Enzyme:使用酶对反应组分中的定制功能进行单元测试

我正在使用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进行单元测试

reactjs enzyme

16
推荐指数
1
解决办法
6124
查看次数

标签 统计

enzyme ×1

reactjs ×1