在私人方法上使用茉莉花 [英] using Jasmines spyon upon a private method

查看:82
本文介绍了在私人方法上使用茉莉花的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在类私有方法上使用Jasmine单元测试框架的spyon方法?

is it possible to use Jasmine unit testing framework's spyon method upon a classes private methods?

文档中提供了此示例,但是对于私有功能来说可以灵活吗?

The documentation gives this example but can this be flexivble for a private function?

describe("Person", function() {
    it("calls the sayHello() function", function() {
        var fakePerson = new Person();
        spyOn(fakePerson, "sayHello");
        fakePerson.helloSomeone("world");
        expect(fakePerson.sayHello).toHaveBeenCalled();
    });
});

推荐答案

只需添加通用参数<任何> spyon()函数:

Just add a generic parameter < any> to the spyon() function:

 spyOn<any>(fakePerson, 'sayHello');

它运行完美!

这篇关于在私人方法上使用茉莉花的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆