酶浅选项。上下文不起作用

时间:2019-08-22 13:45:30

标签: enzyme

我正在研究酶文档,但此示例不起作用:

https://airbnb.io/enzyme/docs/api/ShallowWrapper/context.html

import React, { Component } from 'react';
import { shallow } from 'enzyme';

test('context', () => {
  class MyComponent extends Component {
    render() {
      return <div>{this.context.foo}</div>;
    }
  }

  const wrapper = shallow(<MyComponent />, { context: { foo: 10 } });
  expect(wrapper.context().foo).toBe(10);
  expect(wrapper.context('foo')).toBe(10);
});

结果:

expect(received).toBe(expected)

Expected value to be (using ===):
  10
Received:
  undefined

我做错什么了吗?

以下是代码和框: https://codesandbox.io/embed/react-enzyme-sandbox-8mxxb

0 个答案:

没有答案