有没有办法在验收测试中改变控制器的属性值?
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)
例如,我想在运行测试之前设置输入的默认值。
您可以访问应用程序注册表并查找控制器。
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)
请看一下这个玩意儿