这是我第一次大致了解Jasmine和TDD。我现在正在用Jasmine进行实验,我已经写了一个函数,它只是简单地通过控制台记录一个传入的参数。然后,我正在编写一个测试,以确保使用必要的参数调用函数。
describe("Get suggestions function", function(){
it("Should have parameter - value", function(){
expect(getSuggestions).toThrow();
});
});
上面的代码传入了Jasmine的specrunner,但我不确定这是否是正确的测试方法。
发布于 2015-04-01 23:46:28
您可以使用Jasmine中的toHaveBeenCalledWith函数来实现这一点。
您需要监视getSuggestions函数,然后执行以下操作
it("tracks that the spy was called", function() {
expect(getSuggestions).toHaveBeenCalledWith('foobar');
});
https://stackoverflow.com/questions/29319128
复制相似问题