Reputation: 71
I created an Acceptance test on ember-cli, in order to check when a user is on a URL and then clicks on the "Cancel" button on that page, the page should be redirected to other URL.
When running the test I'm getting this error:
"Promise rejected during Redirects to previous URL if cancel button is clicked: Element .close-button not found".
But I have that element on my template. Could someone suggest me what I'm missing here or suggest me a documentation I can read in order to solved this error?.
This is my acceptance test:
import { test } from 'qunit';
import moduleForAcceptance from '/tests/helpers/module-for-acceptance';
moduleForAcceptance('Acceptance | test/company');
test('Redirects to previous URL if cancel button is clicked', function() {
return visit('test/company/add').then(function(){
return click('.close-button');
}).then(function(assert){
assert.equal(currentURL(), 'test/company');
});
});
I tried this test too, but I keep getting similar error:
test('Redirects to previous URL if cancel button is clicked', function(assert) {
visit('/test/company/add');
click ('.close-button');
andThen(function() {
assert.equal(currentURL(), '/test/company');
});
});
This is the error:
Error: Element .close-button not found.
This is part of the template where I have the cancel button( add.hbs)
<div class="form-add">
<a href="#" class="close-button" {{action 'cancel'}}>Close</a>
</div>
This is the controller, where the action 'cancel' is defined:
actions: {
cancel() {
if (this.get('isSaved')) {
return;
}
this.transitionToRoute('test/company');
}
}
Upvotes: 2
Views: 838
Reputation: 582
Visit and click are the test helpers which will return a promise.Usually you will execute the further testing once your promises are resolved.
Try doing this:
test('Redirects to previous URL if cancel button is clicked', function(assert) {
visit('/test/company/add');
andThen(()=>{
click ('.close-button');
andThen(()=>{
assert.equal(currentURL(), '/test/company');
})
});
});
Upvotes: 2