2
我一直寫燼測試是這樣的:嵌套燼驗收測試助手
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')
});
});
,但我也看到測試寫着「嵌套」的風格是這樣的:
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')
});
});
});
是一種比另一種更好還是更正?第一種風格會成爲競爭條件的來源嗎?
我查閱了一些開源的餘燼應用在GitHub上,看到大部分做我的方式做到這一點:
https://github.com/cowbell/splittypie/blob/master/tests/acceptance/event-test.js
,這裏是嵌套的例子:
https://github.com/HospitalRun/hospitalrun-frontend/blob/master/tests/acceptance/admin-test.js
沒有理由在'andThen'中包裝[異步助手](https://guides.emberjs.com/v2.8.0/testing/acceptance/)。 – steveax
這是我的理解,那麼爲什麼有人會這麼做?我能想象的唯一原因是,如果你包裝它,你可以在異步幫助器上設置一個斷點,否則你不能。 –