我正在尝试在ember组件中测试链接到href属性。与余烬2.0
但是当我用renter hbs渲染组件时,它会渲染以下内容:

<div id=\"23\" class=\"ember-view\">
<p><!----></p>
<div class=\"participantes\">
    <a id=\"ember282\" class=\"ember-view\">
        <span>rnt-ayl-bld-js-jvr-frd-edw</span>
    </a>
</div>



并且href属性未呈现,
我读到这与路由器有关,但是我不确定如何在尝试过的测试中包括路由器:

moduleForComponent('conversation-item', 'Integration | Component | conversation item', {
integration: true,
setup(){
    const router = this.lookup('router:main');
    router.startRouting(true);
}


});

但不存在查找功能


  TypeError:“未定义”不是函数(正在评估
  'container.lookup('router:main')')

最佳答案

您可能想看看这个问题Ember Component Integration Tests: `link-to` href empty

尽管它是1.13,它可能会对您有所帮助。不幸的是,我正在使用ember-mocha,仍然遇到问题。

本质上,您真的很接近,您只需要使用容器来查找路由器。

// tests/helpers/setup-router.js

export default function({ container }) {
  const router = container.lookup('router:main');
  router.startRouting(true);
}


// tests/integration/components/my-component-test.js

import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import setupRouter from '../../helpers/setup-router';

moduleForComponent('my-component', 'Integration | Component | my component', {
  integration: true,
  setup() {
    setupRouter(this);
  }
});

关于javascript - 集成组件中的Emberjs链接到href测试,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34009486/

10-12 06:35