Background
I have a component that yields a block-param. It’s meant to be used like
{{#my-component as |x|}}
Use {{x}} somehow.
{{/my-component}}
Can’t Use Test Helpers
I can’t use ember-test-helper’s test-module-for-component
(or ember-qunit’s moduleForComponent
) because I need the as |x| in the invocation of my-component.
(I’ve opened https://github.com/switchfly/ember-test-helpers/issues/40 as a feature-request for test-module-for-component
to allow specifying block params, but I don’t know exactly how it would do that.
My Unit Test
In the mean time, I’ve tried writing a test. Here’s what I have so far:
import Ember from "ember";
import { moduleFor, test } from "ember-qunit";
import startApp from '../../../../helpers/start-app';
var App;
const TEMPLATE = `
{{#my-component as |x|}}
<span>{{x}}</span>
{{/my-component}}`;
moduleFor('my-component', {
integration: true,
beforeEach: function(assert) {
App = startApp();
const View = App.__container__.lookupFactory('view:default');
this.view = View.create({
tagName: 'section',
template: Ember.Handlebars.compile(TEMPLATE)
});
Ember.run(this.view, 'append');
},
afterEach: function() {
Ember.run(this.view, 'destroy');
Ember.run(App, 'destroy');
App = null;
}
});
test('yields x value', function(assert) {
assert.equal(this.view.$('span').text(), 'x');
});
When I run that, I get
TypeError: Cannot read property 'element' of null
at Object.merge.default.$ (http://localhost:7357/assets/vendor.js:51942:42)
at CoreView.default.extend.$ (http://localhost:7357/assets/vendor.js:53179:32)
at Object.<anonymous> (http://localhost:7357/assets/my-app.js:10105:28)
at Object.wrapper (http://localhost:7357/assets/test-support.js:1785:29)
at Object.Test.run (http://localhost:7357/assets/test-support.js:3443:28)
at http://localhost:7357/assets/test-support.js:3572:11
at process (http://localhost:7357/assets/test-support.js:3131:24)
at begin (http://localhost:7357/assets/test-support.js:3176:2)
at http://localhost:7357/assets/test-support.js:3192:4
That error is happening in hasElement.$
.
Things I Tried
-
Ember.View.create
instead of looking upview:default
on the app, but then the view could findmy-component
-
view.render()
instead ofview.append()
, but that instead gives the error “Cannot read property ‘innerContextualElement’ of undefined” - not specifying
tagName
, but that instead gives the error “You cannot access this.$() on a component withtagName: ''
specified.”