I've always written ember tests like this:
test('should add new post', function(assert) {
visit('/posts/new');
fillIn('input.title', 'My new post');
click('button.submit');
andThen(() => {
assert.equal(find('ul.posts li:first').text(), 'My new post')
});
click('button.edit');
fillIn('input.title', 'My edited post');
click('button.submit');
andThen(() => {
assert.equal(find('ul.posts li:first').text(), 'My edited post')
});
});
but I also see tests written "nested" style like this:
test('should add new post', function(assert) {
visit('/posts/new');
fillIn('input.title', 'My new post');
click('button.submit');
andThen(() => {
assert.equal(find('ul.posts li:first').text(), 'My new post')
click('button.edit');
fillIn('input.title', 'My edited post');
click('button.submit');
andThen(() => {
assert.equal(find('ul.posts li:first').text(), 'My edited post')
});
});
});
Is one way better than the other or correct? Could the first style be a source of race conditions?
I looked up some open source ember apps on github and see most of them doing it the way I do it:
https://github.com/cowbell/splittypie/blob/master/tests/acceptance/event-test.js
and here's an example of nesting:
https://github.com/HospitalRun/hospitalrun-frontend/blob/master/tests/acceptance/admin-test.js