Node.js 未调用Jasmine spy document.execCommand
我写了一个这样的测试Node.js 未调用Jasmine spy document.execCommand,node.js,gruntjs,jasmine,grunt-contrib-jasmine,Node.js,Gruntjs,Jasmine,Grunt Contrib Jasmine,我写了一个这样的测试 describe('execCommand', function () { it('should call document.execCommand', function () { spyOn(document, 'execCommand').and.callThrough(); expect(document.execCommand).toHaveBeenCalledWith('foreColor', false, 'red');
describe('execCommand', function () {
it('should call document.execCommand', function () {
spyOn(document, 'execCommand').and.callThrough();
expect(document.execCommand).toHaveBeenCalledWith('foreColor', false, 'red');
document.execCommand('foreColor', false, 'red');
});
});
但是它没能通过['foreColor',false,'red']调用预期的spy execCommand,但它从未被调用过。
我不知道为什么
请帮忙
注意:我使用
grunt contrib jasmine
0.9.2jasmine的expect
函数运行它时是一个断言,而不是将在it
块末尾运行的断言,请切换顺序以查看它的工作情况:
描述('execCommand',函数(){
它('应该调用document.execCommand',函数(){
spyOn(文档'execCommand')。和.callThrough();
document.execCommand('foreColor',false,'red');
expect(document.execCommand).toHaveBeenCalledWith('foreColor',false,'red');
});
});代码>
Jasmine的expect
函数是当时的断言,而不是将在it
块末尾运行的断言,请切换顺序以查看其工作:
描述('execCommand',函数(){
它('应该调用document.execCommand',函数(){
spyOn(文档'execCommand')。和.callThrough();
document.execCommand('foreColor',false,'red');
expect(document.execCommand).toHaveBeenCalledWith('foreColor',false,'red');
});
});代码>