jasmine spyOn的单步调试

时间:2022-07-28
本文章向大家介绍jasmine spyOn的单步调试,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

如果没有调用fixture.detectChanges, element context的innerHTML里根本就看不到button的源代码:

入口:监控component的next方法调用:

 /**
     * Install a spy onto an existing object.
     * @name spyOn
     * @since 1.3.0
     * @function
     * @global
     * @param {Object} obj - The object upon which to install the {@link Spy}.
     * @param {String} methodName - The name of the method to replace with a {@link Spy}.
     * @returns {Spy}
     */
    spyOn: function(obj, methodName) {
      return env.spyOn(obj, methodName);
    },

env在jasmine.js里实现:

SpyRegistry注册表?

把Component的原始方法Component.next放置到originalMethod变量里。

然后调用createSpy创建spy:

拿到当前运行的spec:

这里能看到deliverymodeComponent的next方法已经是spied版本了:

要获取更多Jerry的原创文章,请关注公众号"汪子熙":