I'm trying to do some basic acceptance tests in Ember, using Mirage. I'm using only fixtures at this point to populate the test environment, just to find my feet. When I run ember in the test environment (i.e., with -e test), I can see my app is populating with expected data. And the DOM has some buttons, etc. All is well.
However, when I run a test to visit a page and click a button, the test is telling me it can't find the button. In other words, running -e test and checking localhost shows the app seems to be fine. But then checking localhost/tests has a test failing saying it can't find a button that is definitely there in the -e test screen.
I've confirmed that the button exists in the -e test environment, using both inspector and just issuing a basic jquery select at the console line.
So I assume there's something wrong in the setup or somewhere in a configuration?
In particular:
module('Acceptance | basic tests', {
beforeEach: function() {
this.application = startApp();
},
afterEach: function() {
Ember.run(this.application, 'destroy');
}
});
test('visiting /orders', function(assert) {
visit('/orders');
andThen(function() {
assert.equal(currentURL(), '/orders');
});
});
test('visiting /basic', function(assert) {
visit('/orders');
click('top-row-orders-button'); //button.top-row-orders-button fails too
andThen(function() {
assert.equal(currentURL(), '/orders');
});
});
The first test (just visiting the url) passes. The second test is where it says it can't find the button. And again, when I serve -e test, and enter this at the console: $('.top-row-orders-button') it returns the button in question.
Happy to provide any more info anyone needs. Would appreciate any help. I've been banging my head on this for a few days now with no luck.
Edited to Add:
More generally, when using Mirage, is there a way to see what the DOM is within the /tests environment (i.e., the DOM that the actual tests are running on)? I.e., what the DOM looks like to each Mirage test?
I ran through ur repository and found that u made the mirage factory configuration wrong...When using
mirageu should define exactly what the app expects.Eg: the api ur calling returns the movies in
Searchobject when running the app. While in tests it returns the movies list object as an reponse. And you made a check in adapters -> query function to return [ ] if there is no Search object.What Mirage does is api mocking. When calling the api it returns the response which u had defined in it's config.js and it still goes through the then promise u had defined in query function in
adapters. Since the model is empty, there in nothing to render and the test failed.Change the mirage config file as
and also change the factories/movie to return the object keys accordingly(say in ur case 'imdbID' not 'id').