Javascript 什么';使用不带sinon服务器的web组件测试仪测试ajax请求的基本模式是什么?
如何使用web component tester和polymer设置以下元素/测试,以便(1)XHR请求完成,(2)然后运行断言,导致(3)测试通过 /my-element.htmlJavascript 什么';使用不带sinon服务器的web组件测试仪测试ajax请求的基本模式是什么?,javascript,ajax,polymer,web-component-tester,Javascript,Ajax,Polymer,Web Component Tester,如何使用web component tester和polymer设置以下元素/测试,以便(1)XHR请求完成,(2)然后运行断言,导致(3)测试通过 /my-element.html <dom-module id="my-element"> <template> <iron-request id="req"><iron-request> </template> <script> (function(
<dom-module id="my-element">
<template>
<iron-request id="req"><iron-request>
</template>
<script>
(function() {
'use strict';
Polymer({
is: 'my-element',
properties: {
newVal: Object
},
fetchedStuff: function(ironRequest) {
this.set('newVal', ironRequest.response);
console.log('This gets logged after tests run.'); // <--- this is firing too late!
},
ready: function() {
this.$.req.resolveCompletes = this.fetchedStuff;
this.$.req.send({url: '/my.json'});
}
});
})();
</script>
</dom-module>
(功能(){
"严格使用",;
聚合物({
是‘我的元素’,
特性:{
newVal:对象
},
fetchedStuff:函数(ironRequest){
this.set('newVal',ironRequest.response);
console.log('这在测试运行后被记录。');//这可能会帮助您:
<test-fixture id="basic">
<template>
<my-element></my-element>
</template>
</test-fixture>
<script>
suite('my-element tests', function() {
test('Item lengths should be equalled', function(done) {
element = fixture('basic');
flush(function() {
assert.equal(element.newVal, {"name": "Polymer"});
done();
});
})
});
</script>