【发布时间】:2018-07-06 02:16:42
【问题描述】:
我正在尝试使用 AngularJS 模拟 CSV Stringify...但我只想获取传入的两个参数并在稍后的测试中使用它们来测试某些选项是否正确。
it("converts latitude and longitude correctly", function() {
this.CSV._stringifyPromise._setResolveMode("instant");
var csvFeatures, csvOptions;
this.CSV.stringify.and.callFake(function(csvFeaturesInStringify,
csvOptionsInStringify) {
csvFeatures = csvFeaturesInStringify;
csvOptions = csvOptionsInStringify;
});
this.featureExportCSVService.buildCsvFile(this.features, "Test");
expect(this.csvOptions[0].LONG).toEqual(this.features[0].geometry.coordinates[
0].toString());
expect(this.csvOptions[0].LAT).toEqual(this.features[0].geometry.coordinates[
1].toString());
});
我相信 CSV stringify 在非测试代码中返回一个承诺,因为它被称为......
CSV.stringify(csvObject.features, csvObject.options)
.then(function(result) { ... }
我以为它只会在我的假电话中返回结果,但这似乎不起作用。
this.CSV.stringify.and.callFake(function(csvFeaturesInStringify,
csvOptionsInStringify) {
expect(...);
expect(...);
return "test,blah,blah";
});
我尝试使用 $q.defer().resolve();,但 $q 未定义。做一个回报它只是说undefined is not a constructor
我将如何解决此函数以仅返回一个虚拟字符串,甚至只是在此处结束测试并评估我的 expect() 调用?
【问题讨论】:
标签: angularjs jasmine karma-jasmine