enyzme调用react方法并期望输出未定义?

时间:2018-07-04 00:54:11

标签: reactjs unit-testing chai enzyme

称为反应功能的酶在返回中未定义?它被调用了,但是我可以用下面的道具来调用它的间谍功能吗?我正在用柴加酶。

//class
export class MyComponent extends Component {
  printSomething = () => 'output'
  render() {
    return (
      <div></div>
    );
  }
}

//spec
describe.only('"handleChange" method', () => {
  beforeEach(() => {
    const MyComponent = mount(<MyComponent />)
    sinon.spy(MyComponent.instance(), 'printSomething')
  })
  it('should call and test printSomething output', () => {

    //some simutlation.. 

    //called
    expect(MyComponent.instance().printSomething).to.have.been.called()

    //failed here? got undefined?
    expect(MyComponent.instance().printSomething()).to.be.equal('output')
  })

0 个答案:

没有答案