当前位置: 动力学知识库 > 问答 > 编程问答 >

reactjs - Mocking ES6 React Components

问题描述:

I am attempting to mock a dependency to one of my ES6 React components, but I think I've really hit a dead end at this point. I've been researching options on google for probably two hours now, but none of the solutions seem to work and I think I've exhausted all options. The last solution I attempted, "babel-preset-rewire," seemed the most promising, but it's throwing an error even when I follow the docs to a T. Here is my attempt at using this babel plugin, but I am also open to other mocking options.

.babelrc

{

"plugins": ["rewire"],

"presets": ["es2015", "react", "stage-0"]

}

Spec

import { SignUp } from './signUp';

SignUp.__Rewire__('TopBarContainer', class TopBarMock {

render() {

return (<div></div>);

}

});

This isn't even extending React.Component, but the goal was just to get something basic working. I can't even seem to get the Rewire function to export with the module... When I try running the above code, the following error message is thrown:

TypeError: _get__(...).Rewire is not a function

分享给朋友:
您可能感兴趣的文章:
随机阅读: