-
-
Notifications
You must be signed in to change notification settings - Fork 155
Integration Test Helpers are undefined in Component Test #88
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
Comments
I made some progress, following test setup + tests is working. I'm not sure if this is the way it is supposed to be or if it is just a workaround? The import { test, moduleForComponent } from 'ember-qunit';
import startApp from '../../helpers/start-app';
import Ember from 'ember';
var App;
moduleForComponent('datepicker-input', 'DatepickerInputComponent', {
setup: function() {
App = startApp();
},
teardown: function() {
Ember.run(App, 'destroy');
}
});
test('is an input tag', function() {
equal('INPUT', this.$().prop('tagName'));
this.subject().teardownPikaday();
});
test('clicking the input opens the pikaday dialog', function() {
this.append();
ok($('.pika-single').hasClass('is-hidden'));
click('input');
andThen(function() {
ok(!$('.pika-single').hasClass('is-hidden'));
});
this.subject().teardownPikaday();
}); |
I had the same issue and the same solution. importing startApp and creating it in setup/teardown worked for me. |
Why not just trigger the jQuery click directly (which is essentially what the Something like: moduleForComponent('datepicker-input');
test('clicking the input opens the pikaday dialog', function() {
var component = this.subject();
this.append();
ok(component.$('.pika-single').hasClass('is-hidden'));
component.$('input').click();
ok(!component.$('.pika-single').hasClass('is-hidden'));
component.teardownPikaday();
}); |
The integration test helpers are wonderful, but they do not belong in unit tests IMHO. |
That's seems fair to me. Ok to do some light DOM testing in component unit tests, but if you want to do heavy user interaction, make an integration test for the component. |
I don't think this should be closed. The intent is not that there is a bug in ember (or cli) but that the documentation is wrong and misleading. Specifically:
The first paragraph sets the reader's expectation that testing components are unit tests. Further more, the first reference to integration is:
This gives the reader the impression that although this is a unit test you can cross contaminate methods from integration helpers. The confusion for the error reported by the original poster is most likely a byproduct of not including This is further reinforced by the fact that the code samples never reference moduleForComponent('my-foo', 'MyFooComponent');
// ERROR! -----------------------------------^
// Will crash with "unable to read property 'needs' of undefined"
// This is because moduleForComponent with two paramaters requires a third
// object (for needs, beforeEach, afterEach, etc.) and probubly an assumption
// that the user will call setupApp() because this is somehow a integration
// test even though the docs claim it is a unit test.
test('clicking link updates the title', function() {
// WTF?! where is my assert? ------------------^
var component = this.subject();
// append the component to the DOM
this.append();
// ^- But wait the above example said "first call to $() renders the
// component." Which do I use?!
// Also aren't we missing assert.expect() ?!
// assert default state
equal(find('h2').text(), 'Hello World');
// ^- What happened to assert.equal?! So confused please help!
// perform click action
click('button');
// ^-- NO! Crash again! Why? Oh why? ლ(ಠ益ಠლ)
andThen(function() { // wait for async helpers to complete
equal(find('h2').text(), 'Hello Ember World');
// ^-- How does this differ from this.$() ?
});
}); The point being that it not fair to end the topic when the documentation hasn't been updated / fixed. Finally, EDIT: Just found the guides repo so I should put my 💵 where my mouth is and work on a Pull Request. |
Just a note for noobs like me who end up here, adding this to the test imports the helpers for "integration" tests: moduleForComponent('my-component', 'myComponent', {
integration: true
}); |
I'm having this problem right now in v2.9.1 I have: in ANY component test, if I do assertTrimmedText(stuff) I get told: |
I have the same problem as @rstudner. |
Please open a new issue with steps to reproduce. 😝 Commenting on an issue closed for over a year is pretty unlikely to work out... |
I'm writing a tutorial about creating Ember Addons / Components. Since it is a datepicker component I want to test various user interactions on the component.
These tests fail because the helpers
click
etc. are not defined. I'm following the official Ember.js guide and it fails. I'm not sure if this is a problem on my end or something is broken?Related SO question: http://stackoverflow.com/questions/25657787/acceptance-testing-a-ember-datepicker-component-with-ember-cli
The text was updated successfully, but these errors were encountered: