我在對函式進行單元測驗時遇到了一些困難。我是這些事情的新手,我不知道我能做什么。我必須要那些 2 如果。
有什么建議嗎?謝謝你。
uj5u.com熱心網友回復:
我認為你的問題是jasmine.createSpy(phoneNumber);,因為這個方法正在測驗中,我們不應該監視它,而應該實際呼叫它的實作。
嘗試以下操作:
it('should remove outside prefix', () => {
const dialingOptions = {
reqLongDistPrefix: 10, reqOutsidePrefix: 11, dialLongDistanceLength: 12
} as any;
coreSvc.getCCDef = jasmine.createSpy().and.returnValue({ DialingOptions: dialingOptions });
let phoneNumber = '1011129999';
// !! Remove the following line !!
// component.removeOutsidePrefix = jasmine.createSpy(phoneNumber);
const modifiedPhoneNumber = component.removeOutsidePrefix(phoneNumber);
// !! below is not a good assertion, you can remove it
// expect(Object.keys(dialingOptions).length).toBe(3);
expect(modifiedPhoneNumber).toBe('insert what you expect it to be here');
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/475374.html
上一篇:柴應該是大數相等不起作用
