语法:expect(传入一个被spied后的方法).matcher检查
el.focus是spied method:
expect函数返回的是一个matcher:
进行toHaveBeenCalled的matcherFactory:
Expector原型链上的compare方法逻辑:首先生成一个matcher实例,然后使用apply的方式动态调用之:
spy函数的and属性就是SpyStrategy,其Plan属性返回的就是andReturnValue里指定的值。
calls属性就是调用tracker.
expect(wrapped spied method)返回的expectation,是否通过,取决于toHaveBeenCalled方法里第735行:
只要calls里至少有一条记录,expectation就算pass:
更多Jerry的原创文章,尽在:“汪子熙”: