Я новичок, чтобы реагировать на развитие. Я пытаюсь написать тестовый блок для следующего класса.
export default class MyButton extends Component {
componentDidMount() {
this.context.someObject.status();
}
render() {
return (
<div> hello </div>
);
}
}
MyButton.contextType = MyContext;
Я пытался написать блок-тесты с использованием фермента.
describe('MyButton', () => {
it('MyButton should render properly', () => {
const MyContext = React.createContext({ someObject: {status : () => null} });
const wrapper = shallow(< MyButton />, {context: MyContext});
});
});
Но я получаю эту ошибку. TypeError: Cannot read property 'status' of undefined