4
votes

I have a component test that is failing because it can't find a partial that the template is rendering. The specific error is "Assertion Failed: Unable to find partial with name 'components/activity-list-item-content'."

My test file is basically the default generated by ember-cli:

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

moduleForComponent('activity-list-item', 'ActivityListComponent', {
  // specify the other units that are required for this test
  needs: ['helper:format-date']
});

test('it renders', function() {
  expect(2);

  // creates the component instance
  var component = this.subject();
  equal(component._state, 'preRender');

  // appends the component to the page
  this.append();
  equal(component._state, 'inDOM');
});

and the component template that looks like this:

{{#if activity.momentId}}
  {{#link-to 'moment' momentId class='close-dropdown'}}
    {{partial 'components/activity-list-item-content'}}
  {{/link-to}}
{{else}}
  {{partial 'components/activity-list-item-content'}}
{{/if}}

My application is working fine without any errors, so I'm wondering if it's something missing from my test setup. I've also tried adding it to the needs array and get the same error:

needs: ['helper:format-date', 'template:components/-activity-list-item-content']

How do I get my tests to find the partial?

Update

@GJK pointed out that the partial name should start with an underscore instead of a dash. If I make that change, the test passes, however I get a depcrecation warning in the console that says:

DEPRECATION: Modules should not contain underscores. Attempted to lookup "myapp-ember/templates/components/-activity-list-item-content" which was not found. Please rename "myapp-ember/templates/components/_activity-list-item-content" to "myapp-ember/templates/components/-activity-list-item-content" instead.

1
Partial names must start with an underscore (not a dash). Maybe that's your problem?GJK
@GJK if I change to an underscore, I get this error: DEPRECATION: Modules should not contain underscores. Attempted to lookup "myapp-ember/templates/components/-activity-list-item-content" which was not found. Please rename "myapp-ember/templates/components/_activity-list-item-content" to "myapp-ember/templates/components/-activity-list-item-content" instead.Peter Brown
It looks like maybe an incompatibility with ember-cli? github.com/stefanpenner/ember-cli/issues/2097Peter Brown
Considering the example in the docs (ember-cli), why not name the partials without hyphens or underscores?Patsy Issa
@PatsyIssa that did the trick, thanks! I wonder why they suggest that partials need to start with a hyphen or underscore when it's not really required.Peter Brown

1 Answers

0
votes

Found this issue: https://github.com/rwjblue/ember-qunit/issues/110

The current workaround is:

import resolver from '../../helpers/resolver';

moduleForComponent('some-other-thing', 'component:some-other-thing', {
  needs: ['component:some-thing'],

  setup: function() {
    this.container.register('template:path/to/partial', 
           resolver.resolve('template:path/to/-partial'));
  }
});