【发布时间】:2022-08-17 20:58:46
【问题描述】:
我试图弄清楚如何断言使用createSpyObj 创建的属性已被访问并且我遇到了砖墙。
describe(\'spyObjectTest\', () => {
it(\'should create a spy object and assert it was accessed\', () => {
const spyObj = jasmine.createSpyObj(
\'spyObj\',
{},
{
x: \'foo\',
y: \'bar\',
z: \'fubar\',
}
);
// Spy object is accessed here...
console.log(spyObj.x, spyObj.y, spyObj.z);
// I get this useless error. how is x not a spy?
// Error: <toHaveBeenCalled> : Expected a spy, but got \'foo\'.
// Usage: expect(<spyObj>).toHaveBeenCalled() (line 5180)
expect(spyObj.x).toHaveBeenCalled();
expect(spyObj.y).toHaveBeenCalled();
expect(spyObj.z).toHaveBeenCalled();
});
});
我要做的就是检查这些应该是间谍的属性是否已被访问。有没有办法做到这一点?
标签: jasmine karma-jasmine karma-runner