Jamine如何使用回调模拟接口

时间:2017-02-23 04:01:22

标签: unit-testing typescript knockout.js jasmine typescript-typings

我是Jamine测试框架的新手,目前我有模拟界面的问题。有人可以帮助我吗?

界面如下:

interface MessengerSubscribe {
    onSystemLoggedIn(callback: (data: INotLoggedinInfo) => void): MessengerSubscription;
    onSessionTimedOut(callback: () => void): MessengerSubscription;
    onHasEssBalance(callback: () => void): MessengerSubscription;
}

这是我尝试过的不起作用。

let mockMessenger: MessengerStatic = {
        subscribe: {
            onSystemLoggedIn: () => <MessengerSubscription>
        }
    };

这是消息说明:

interface MessengerSubscription {
    dispose(): void;
}

1 个答案:

答案 0 :(得分:0)

一个简单的模拟看起来像:

let mockMessenger: MessengerSubscribe = {
    onSystemLoggedIn: (callback: any): any => {},
    onSessionTimedOut: (callback: any): any => {},
    onHasEssBalance: (callback: any): any => {}
};