Ember组件集成测试:`link-to` href为空 [英] Ember Component Integration Tests: `link-to` href empty

查看:141
本文介绍了Ember组件集成测试:`link-to` href为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试撰写组件集成测试,此博客文章,但是我的组件有一个链接到到动态路由,而 href 属性不是这是我想要做的简化版本。

I'm trying to write a component integration test, a la this blog post, but my component has a link-to to a dynamic route and the href property isn't being filled in. Here is a simplified version of what I'm trying to do.

我的组件模板:

{{#link-to "myModel" model}}

这里是我测试的相关部分:

And here is the relevant part of my test:

this.set('model', {
  id: 'myId',
  name: 'My Name'
});

this.render(hbs`
{{my-component model=model}}
`);

assert.equal(this.$('a').attr('href'), '/myModel/myId'); // fails

link-to 渲染,只是没有一个 href 属性。如果我在测试中记录HTML,它看起来像:

The link-to is rendered, just without an href attribute. If I log the HTML in the test, it looks like:

<a id="ember283" class="ember-view">My Name</a>

有什么我需要做的我的模型来获取链接到有一个href?我试图查看ember中 link-to 的测试,并发现这部分测试,这基本上是我在做的 - 提供一个POJO与 id 键集。任何想法?

Is there something I need to do to my "model" to get the link-to to have an href? I tried to look at the tests for link-to in ember, and found this part of the tests, which is basically what I'm doing – provide a POJO with the id key set. Any ideas?

编辑:

DEBUG: -------------------------------
DEBUG: Ember      : 1.13.8
DEBUG: Ember Data : 1.13.10
DEBUG: jQuery     : 1.11.3
DEBUG: -------------------------------


推荐答案

路由器并告诉它在您的测试设置中启动路由,它将工作。从@rwjblue的此提交

Turns out you can just look up the router and tell it to start routing in your test setup and it will work. From this commit from @rwjblue:

// 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);
  }
});

这篇关于Ember组件集成测试:`link-to` href为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆