-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
added ember-testing integration test for issue #2997 #3026
Conversation
for those of us unfamiliar with the issue can u describe the failure in words as well? |
When I was integration testing with ember.js RC5 and I wanted to hit the "/" route of my app using visit, the route handler would invoke the model function both when the app was started and when I hit the "visit" line in my test code. This allowed me to modify what would occur in the model hook just before calling "visit" In the test I attached, I stub out what the xhr should return before calling visit("/"). In RC5 this worked great but for some reason in RC6 it won't fire the model hook a second time (as it already fired when the app was loaded I assume). The happy-path should be that when I want to visit a route, the model method will fire when my test code is executed (so I can setup the state of the application for example). Thank you in advance |
For anyone watching this issue, it's still broken in ember.js RC7 |
I updated the unit test, it helped me find the offending commit that broke this behavior |
I just ran into this issue also. Thanks @toranb for getting this issue out there! |
+1 |
I'd like to see this fixed so we can upgrade from RC5. +1 |
👍 |
Would also be very interested in a fix! |
@stefanpenner I just updated the test after our pairing session and it's GREEN my friend. Can you pull it in before you go live w/ RC8 ? |
absolutely. I think the implicit 'visit("/")' that occurs during testing today isn't ideal. Rather requiring an explicit visit might be better. Although that comes with it's own caveats, it may be the easier to teach and explain. |
added ember-testing integration test for issue #2997
Thanks @toranb and @stefanpenner for this. I do have questions / comments. Is the testing API for getting my Ember app to an initial state that in my App.setupForTesting();
App.reset();
App.deferReadiness();
App.injectTestHelper(); then inside each test I call: App.advanceReadiness(); and in my App.revmoveTestHelpers();
Ember.$('#ember-testing').remove();
Ember.run(App, App.destroy);
App = null; I think this test is a good demonstration of how to reset your Ember app, however I do not think it is a very real world-like example. The I'm not sure that I can write the test that I want to be able to write with the implicit test("shows list of user groups", function(){
jQuery.mockjax({
type: 'GET',
url: '/groups',
status: 200,
dataType: "json",
responseText: {'groups': [
{ id: 1, name: 'Group One'}
]}
});
visit('/').then(function(){
var group = find(".groups li:eq(0)").text();
equal(group, "Group One", group + " was incorrect");
});
}); Currently (as of rc7), I have not been able to write this test because (I believe) of the implicit visit('/') even after playing around with some of the methods used in this pull request's test example. I do not want to override the Is there something that I'm missing that will be able to reset the entire state of my Ember app so that when I |
@mattjmorrison i think the implicit visit that occurs today on
What likely needs to happen today. setup: function(){
Ember.run(function(){
App.reset();
App.deferReadiness(); // prevents the app for booting, and starting to route.
});
};
test("shows list of user groups", function(){
jQuery.mockjax({
type: 'GET',
url: '/groups',
status: 200,
dataType: "json",
responseText: {'groups': [
{ id: 1, name: 'Group One'}
]}
});
// app has not finished booting yet.
Ember.run(App, 'advanceReadiness');
// Assuming all async was correctly stubbed out, your app should now be in '/
// please note, in your example u where visiting / a second time.
var group = find(".groups li:eq(0)").text();
equal(group, "Group One", group + " was incorrect");
}); Proposal for the near future: (explicit visit) setup: function(){
App.reset();
};
test("shows list of user groups", function(){
// no implicit 'visit' has happened
// so feel free to mock
jQuery.mockjax({
type: 'GET',
url: '/groups',
status: 200,
dataType: "json",
responseText: {'groups': [
{ id: 1, name: 'Group One'}
]}
});
// explicit visit required
visit('/').then(function(){
var group = find(".groups li:eq(0)").text();
equal(group, "Group One", group + " was incorrect");
});
}); |
I've added a test to show the before and after of this scenario to show that no state is being leaked across tests |
Erik
I added the failing scenario as a test so you have something to start with. Note- it's not 100% functional because I didn't know how you would want to pull in jQuery for the actual test (or if you would prefer to avoid it at all costs and do something else instead).
Either way, you can take parts from what I have here or roll your own. I just wanted to have an example up to help move this along so we can hit 1.0 :)
Thanks again for all the help on this issue
Toran