Javascript Jasmine 2.0:如何在所有单元测试中使用来自单个ajax调用的数据
我希望避免在Jasmine中的每个测试之前运行ajax调用。 相反,我想在所有测试中使用来自单个ajax调用的数据,有没有办法做到这一点 目前我正在使用beforeach,如下所示:Javascript Jasmine 2.0:如何在所有单元测试中使用来自单个ajax调用的数据,javascript,unit-testing,jasmine,Javascript,Unit Testing,Jasmine,我希望避免在Jasmine中的每个测试之前运行ajax调用。 相反,我想在所有测试中使用来自单个ajax调用的数据,有没有办法做到这一点 目前我正在使用beforeach,如下所示: beforeEach(function(done) { $.ajax({ url: '/vulnerability/data', success: function (response) { done(); }, dataTyp
beforeEach(function(done) {
$.ajax({
url: '/vulnerability/data',
success: function (response) {
done();
},
dataType: 'html'
});
});
it("test 1", function() {
// ajax is called for the 1st time
// this won't run until the done callback is invoked from the beforeEach
});
it("test 2", function() {
// ajax is called for the 2nd time
// this won't run until the done callback is invoked from the beforeEach
});
it("test N", function() {
// ajax is called for the Nth time
// this won't run until the done callback is invoked from the beforeEach
});
在Jasmine 2.1中,您可以在之前使用
。在以前的版本中,这个插件:啊,很好,这是一个完美的解决方案,谢谢您在Jasmine 2.1中,您可以在之前使用
。在以前的版本中,这个插件:啊,很好,这是完美的解决方案,谢谢