Skip to content

Example of a component test using can() helper? #13

@acorncom

Description

@acorncom

This is related to #8, but different. I worked through doing unit tests of our abilities and seem to have acceptance tests (with full use of initializers and the container) running smoothly, but I'm hitting some snags when trying to run a contained unit test of a component.

I hit this one first:

Error: Assertion Failed: A helper named 'can' could not be found
    at new Error (native)
    at Error.EmberError (http://localhost:7357/assets/vendor.js:22557:21)
    at Object.Ember.default.assert (http://localhost:7357/assets/vendor.js:15711:13)
    at subexpr (http://localhost:7357/assets/vendor.js:17935:11)
    at Object.render (http://localhost:7357/assets/backend.js:1956:44)
    at renderHTMLBarsTemplate (http://localhost:7357/assets/vendor.js:18388:21)
    at renderView (http://localhost:7357/assets/vendor.js:18355:16)
    at renderView (http://localhost:7357/assets/vendor.js:47271:5)
    at mixin.Mixin.create.render (http://localhost:7357/assets/vendor.js:47292:7)
    at EmberRenderer_createElement [as createElement] (http://localhost:7357/assets/vendor.js:49416:14)

The below seems to resolve that issue (although I wonder if we should make a test helper to make this simpler and ease implementation changes in the future? I might be able to help there ...):

import Ember from 'ember';
import { moduleForComponent, test } from 'ember-qunit';

import helper from 'backend/helpers/can';

moduleForComponent('sidebar-menu', {
  beforeEach: function() {
    Ember.HTMLBars._registerHelper('can', helper);
  }
  // specify the other units that are required for this test
  //needs: ['component:foo', 'helper:bar']
});

But now I'm hitting a second error regarding auto-loading abilities:

Error: Assertion Failed: No ability type found for forms
    at new Error (native)
    at Error.EmberError (http://localhost:7357/assets/vendor.js:22557:21)
    at Object.Ember.default.assert (http://localhost:7357/assets/vendor.js:15711:13)
    at exports.default (http://localhost:7357/assets/vendor.js:84566:22)
    at subexpr (http://localhost:7357/assets/vendor.js:17940:34)
    at Object.render (http://localhost:7357/assets/backend.js:1956:44)
    at renderHTMLBarsTemplate (http://localhost:7357/assets/vendor.js:18388:21)
    at renderView (http://localhost:7357/assets/vendor.js:18355:16)
    at renderView (http://localhost:7357/assets/vendor.js:47271:5)
    at mixin.Mixin.create.render (http://localhost:7357/assets/vendor.js:47292:7)

The app/abilities/forms.js ability is properly setup and works in the UI (and in acceptance tests). But thinking about it, in essence I'm running a mini-acceptance test (just for a component). Which would be why the initializers you use to setup the abilities aren't working.

Any suggestions / pointers on how to handle things here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions