简体   繁体   English

sinon伪造的xhr服务器和聚合物appLocalizeBehavior语言环境

[英]sinon fake xhr server and polymer appLocalizeBehavior locales

I am developing a web frontend using Polymer. 我正在使用Polymer开发Web前端。 I have a webcomponent which uses other webcomponents, for example a paper-input or some custom webcomponents. 我有一个使用其他Web组件的Web组件,例如纸张输入或某些自定义Web组件。 For demo purposes i am using the sinon fake xhr server to mock some elasticsearch requests, which is really nice for testing. 出于演示目的,我正在使用sinon伪造的xhr服务器来模拟一些Elasticsearch请求,这对于测试来说真的很不错。 In the webcomponents i use the polymer appLocalizeBehavior to load some locales from a json file. 在Web组件中,我使用聚合物appLocalizeBehavior从json文件加载某些语言环境。 AppLocalizeBehavior uses iron-request to load the files via an url. AppLocalizeBehavior使用iron-request通过URL加载文件。 I configured sinon to filter and exclude all urls including "locales.json", like this: 我将sinon配置为过滤和排除包括“ locales.json”在内的所有网址,如下所示:

this._server = sinon.fakeServer.create();
this._server.autoRespond = true;
this._server.xhr.useFilters = true;
this._server.xhr.addFilter(function(method, url) {
    return url.includes("locales.json");
});

If i disable the xhr fake server the locales from all components are loading correctly. 如果禁用xhr伪造服务器,则所有组件的语言环境都将正确加载。 But if i enable sinon it seems like the locales are beeing loaded but sinon somehow returns them with a wrong encoding. 但是,如果我启用了sinon,似乎语言环境正在加载,但是sinon会以某种错误的编码返回它们。

Someone out there facing similar problems? 有人面临类似的问题吗?

There is a pull request in pending to resolve this issue: https://github.com/sinonjs/nise/pull/45 有待处理的拉取请求可以解决此问题: https : //github.com/sinonjs/nise/pull/45

If you want to solve it locally, then in your sinon.js file, from your bower_components folder, you have to replace this line of code: 如果要在本地解决问题,则必须在bower_components文件夹中的sinon.js文件中,替换以下代码行:

copyAttrs(["responseText", "response"]);

with this one: 与此:

copyAttrs(["responseText", "response", "responseType"]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM