用玩笑+酶+ react-redux测试propType的最佳实践?

时间:2018-07-31 13:37:02

标签: javascript reactjs react-redux jestjs enzyme

我尝试了很多在google上找到的解决方案,以测试use Auth; public function toMail($notifiable) { return (new MailMessage) ->greeting('Dear'.$this->user->name.'thak you for creating donation for '.$this->book->name); } 是否在React组件上设置正确,但是没有一个对我有用。即使在属性不正确传递的情况下在浏览器上运行React应用程序时收到控制台警告,但当我开玩笑时,我无法以任何尝试的方式捕获该警告。这是我的最佳尝试:

App.js:

Component.propTypes

App.test.js:

export class App extends Component {
    constructor(props) {
        super(props);
    }

    render() {
        return <div/>;
    }
}


App.propTypes = {
    images: PropTypes.array.isRequired
};

function mapStateToProps(state) {
    const {images} = state;
    return {images: images};
}

export default connect(mapStateToProps)(App);

1 个答案:

答案 0 :(得分:-1)

根据我在各种GitHub问题线程上在线阅读的内容,似乎一种常见的方法是抛出console.warn/console.error

因此,在编写测试时,您可以执行类似的操作

expect(// Render Component //).to.throw();

希望这会有所帮助。

更多信息:https://github.com/airbnb/enzyme/issues/588