0
なぜテスト用IDで 'new ServerNotificationApi'を書くとコンストラクタが呼び出されないのですが、new ServerNotificationApi.constructor()
が動作しますが、なぜ書くのか分かりません。new ServerNotificationApi
ユニットテストでエラーが発生しました。 '_ Type_Result:_serverNotifications.defaultはコンストラクタではありませんあなたが輸出している「なぜ、es6にコンストラクタが必要ですか?
クラス
class ServerNotificationApi {
constructor() {
SignalR.initConnection(url.serverNotificationHubName)
}
subscribe = callback => SignalR.subscribe(url.entityChanged, url.serverNotificationHubName, callback);
unsubscribe = callback => SignalR.unsubscribe(url.entityChanged, url.serverNotificationHubName, callback);
}
export default new ServerNotificationApi()
テスト
it('constructor should call signalR method \'initConnection\'',() => {
sinon.stub(SignalR, 'initConnection')
new ServerNotificationApi.constructor()
SignalR.initConnection.calledWith(url.serverNotificationHubName).should.be.true
SignalR.initConnection.restore()
})