我正试图用jest测试一个反应组件,这看起来像:
class UserOnSamePageAlert extends React.Component {
constructor(props) {
super(props);
this.state = {
connected_users: []
};
// subscribe to channel to know if a user is on the same page
this.onSamePageChannel = new OnSamePageSubscription({
current_user: sessionStorage.getItem('current_user'),
url: props.urlToSubscribe,
onUpdate: this.onUserAction,
});
}
... more code here ...
}
我的OnSamePageSubscription组件:
export default class OnSamePageSubscription extends React.Component {
constructor(props) {
super(props);
... more code here ...
}
... more code here ...
}
这项工作很好,但我认为这不是测试目的的好方法。 我认为我必须注入OnSamePageSubscription对象,进行单元测试。
我的问题是: