如何在验收测试中更改控制器的属性值?

Lor*_*lor 2 ember.js

有没有办法在验收测试中改变控制器的属性值?

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'));
});
Run Code Online (Sandbox Code Playgroud)

例如,我想在运行测试之前设置输入的默认值。

Ebr*_*ani 5

您可以访问应用程序注册表并查找控制器。

moduleForAcceptance设置应用程序。

test('should add new post', function(assert) {
  let controller = this.application.__container__.lookup('controller:posts/new');  
  controller.set('val', 'default');

  visit('/posts/new');
  fillIn('input.title', 'My new post');
  click('button.submit');
  andThen(() => assert.equal(find('ul.posts li:first').text(), 'My new post'));
});
Run Code Online (Sandbox Code Playgroud)

请看一下这个玩意儿