Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
acorncom opened this issue Apr 14, 2015 · 1 comment
Closed

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

acorncom opened this issue Apr 14, 2015 · 1 comment

Comments

@acorncom
Copy link

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?

@blimmer
Copy link
Contributor

blimmer commented Jul 3, 2015

You're running into two issues here.

The first (helper 'can' not found) is because before Ember 1.13, helpers without dashes were not allowed (RFC). That has been resolved in 1.13, so you should just be able to needs: ['helper:can'] instead of running the initializer in your beforeEach.

The second issue you're running into is because the resolver does not know how to look up abilities in the file structure. This, too, is a pretty easy fix. Simply add this line to your tests/helpers/resolver.js file:

resolver.pluralizedTypes.ability = 'abilities';

Then needs: ['abilitiy:foo'] in your test. That should get you up and running.

I've placed an example you can look at here. You'll probably want to check out the resolver.js and test.

I'm also going to make a PR with documentation updates to help people along with testing.

blimmer added a commit to blimmer/ember-can that referenced this issue Jul 3, 2015
blimmer added a commit to blimmer/ember-can that referenced this issue Jul 3, 2015
blimmer added a commit to blimmer/ember-can that referenced this issue Jul 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants