Open Christian-health opened 6 years ago
JavaScript单元测试框架-Jasmine 原文地址: http://www.cnblogs.com/zhcncn/p/4330112.html
http://oomusou.io/jasmine/jasmine-spy/#Spy#calls
若 Spy 被呼叫一次以上,則傳回 true,否則傳回 false。
it(`should use getTitle()`, () => {
const spy = spyOn(component, 'getTitle');
fixture.detectChanges();
expect(spy.calls.any()).toBeTruthy();
});
測試 spy.calls.any(),若曾被呼叫過為 true,否則為 false。 這種寫法等效於:
it(`should use getTitle()`, () => {
const spy = spyOn(component, 'getTitle');
fixture.detectChanges();
expect(spy).toHaveBeenCalled();
});
傳回 Spy 被呼叫的次數。
it(`should use getTitle() for once`, () => {
const spy = spyOn(component, 'getTitle');
fixture.detectChanges();
expect(spy.calls.count()).toBe(1);
});
測試 spy.calls.count(),可精確測試 Spy 被呼叫的次數。 這種寫法等效於:
it(`should use getTitle() for once`, () => {
const spy = spyOn(component, 'getTitle');
fixture.detectChanges();
expect(spy).toHaveBeenCalledTimes(1);
});
jasmine函数库: 比如能查看到:
.calls.mostRecent(): returns the context (the this) and arguments for the most recent call
.calls.mostRecent():返回最近一次调用的上下文(this)和参数
suite 测试集
tear(眼泪) down 拆除
specs 测试用例
前端测试-jasmine
原文地址: http://www.jianshu.com/p/cbfbfe65d777
笔记: toEqual,toBeTruthy()方法和toBeFalsy()方法详细解释:
https://www.safaribooksonline.com/library/view/javascript-testing-with/9781449356729/_yes_or_no_tobetruthy_tobefalsy.html
自定义matcher没看如何实现。