Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/432.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 什么';使用不带sinon服务器的web组件测试仪测试ajax请求的基本模式是什么?_Javascript_Ajax_Polymer_Web Component Tester - Fatal编程技术网

Javascript 什么';使用不带sinon服务器的web组件测试仪测试ajax请求的基本模式是什么?

Javascript 什么';使用不带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(

如何使用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() {
      '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>