我写了一个这样的测试
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');
});
});但是Expected spy execCommand to have been called with [ 'foreColor', false, 'red' ] but it was never called.失败了,我不知道为什么?
请帮帮忙。
注意:我使用grunt-contrib-jasmine 0.9.2运行它。
发布于 2016-05-13 10:38:50
Jasmine的expect函数当时是一个断言,而不是一个将在it块末尾运行的断言,请切换顺序以确保它正常工作:
describe('execCommand', function () {
it('should call document.execCommand', function () {
spyOn(document, 'execCommand').and.callThrough();
document.execCommand('foreColor', false, 'red');
expect(document.execCommand).toHaveBeenCalledWith('foreColor', false, 'red');
});
});<link href="//safjanowski.github.io/jasmine-jsfiddle-pack/pack/jasmine.css" rel="stylesheet" />
<script src="//safjanowski.github.io/jasmine-jsfiddle-pack/pack/jasmine-2.0.3-concated.js"></script>
https://stackoverflow.com/questions/37207643
复制相似问题