我试图在logo-manager.component.ts文件中测试一个静态函数,但该函数不在"导出类LogoManager";
export class LogoManagerComponent implements OnInit {
...
}
function dataURLtoFile(dataurl, filename) {
...
}
我试着在像这样的logo-manager.component.spec.ts中进行导入
import * as LogoManagerObj from './logo-manager.component';
然后
const fileObject = getFakeEventData({name: 'name', type: 'image/png', size: 500});
spyOn(LogoManagerObj, 'dataURLtoFile').and.returnValue(fileObject);
但是我得到了类型为"的错误Argument;dataURLtoFile"不可分配给类型为"的参数;LogoManagerComponent"。
除了尝试spyOn,我还尝试了spyOnProperty,但没有成功。
提前感谢您的评论。
dataURLtoFile
在LogoManagerObj
中不存在。
尝试以下操作:
export class LogoManagerComponent implements OnInit {
...
}
export function dataURLtoFile(dataurl, filename) { // add export here
// so we can have a handle on it in the tests
...
}
import * as LogoManagerObj from './logo-manager.component';
.....
const fileObject = getFakeEventData({name: 'name', type: 'image/png', size: 500});
spyOn(LogoManagerObj, 'dataURLtoFile').and.returnValue(fileObject);
// to get a handle on the component, it would be LogoManagerObj.LogoManagerComponent