单元测试emberjs组件包含"链接到"

时间:2014-04-02 16:23:16

标签: ember.js qunit

我正在使用ember-qunit moduleForComponent帮助程序,它运行良好。

问题是,当我测试呈现的HTML @$('.myclass')时,我收到以下错误:

TypeError: Cannot read property 'router' of undefined

关联的HBS文件包含:

{{#link-to 'units.options' (query-params categoryId=category.id)}} 

单元测试包含:
    import { test, moduleForComponent } from 'ember-qunit'

`import Router from 'appkit/router'`

moduleForComponent('category-card')

test 'card title', ->
  component = @subject()

  Ember.run ->
    component.set 'category', Ember.Object.create(id: 34, name: 'extra large')

  equal(@$('.card-title').text(), 'extra large')

似乎我需要存根路由器。有什么提示吗?

TypeError: Cannot read property 'router' of undefined
    at computeLinkViewRouteArgs (http://localhost:7359/vendor/ember/ember.js:37627:66)
    at ComputedPropertyPrototype.get (http://localhost:7359/vendor/ember/ember.js:4926:38)
    at get (http://localhost:7359/vendor/ember/ember.js:2151:17)
    at computeLinkViewLoading (http://localhost:7359/vendor/ember/ember.js:37493:12)
    at ComputedPropertyPrototype.get (http://localhost:7359/vendor/ember/ember.js:4926:38)
    at get (http://localhost:7359/vendor/ember/ember.js:2151:17)
    at computeLinkViewActive (http://localhost:7359/vendor/ember/ember.js:37463:11)
    at ComputedPropertyPrototype.get (http://localhost:7359/vendor/ember/ember.js:4926:38)
    at get (http://localhost:7359/vendor/ember/ember.js:2151:17)
    at Ember.View.Ember.CoreView.extend._classStringForProperty (http://localhost:7359/vendor/ember/ember.js:23738:15)

1 个答案:

答案 0 :(得分:0)

这对我有用

setup: ->
    store = QUnit.Helpers.configureStore @container
    Ember.LinkView.reopen({
      href: '#'
      loading: {}
    })