【发布时间】:2016-09-23 15:56:25
【问题描述】:
我总是这样写 ember 测试:
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 上查找了一些开源 ember 应用程序,发现它们中的大多数都按照我的方式进行操作:
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
【问题讨论】:
-
没有理由将async helpers 包裹在
andThen中。 -
这是我的理解,为什么会有人这样做呢?我能想象的唯一原因是,如果你包装它,你可以在异步助手上设置断点,否则你不能。
标签: ember.js ember-cli acceptance-testing