如何在ember中存储组件的动作? [英] How to stub component's action in ember?

查看:160
本文介绍了如何在ember中存储组件的动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个组件,其操作使用存储服务。如何从集成测试中存储此操作?

I created a component, whose action uses store service. How can I stub this action from integration test?

// app/components/invoice-form.js
export default Ember.Component.extend({
  actions: {
    loadPartners() {
      let self = this;
      this.get('store').findAll('partner').then(function(partners) {
        self.set('partners', partners);
      });
    }
  }
});

在此组件的模板中,我将此操作作为闭包传递给子组件:

In this component's template I pass this action as closure to child component:

{{button-confirmation text="Are you sure?" onConfirm=(action "loadPartners")}}

在我的集成测试中,我像往常一样渲染组件

In my integration test, I render the component as usual

this.render(hbs`{{invoice-form}}`);

动作loadPartners不作为参数传递给组件助手。它只是静态组件的动作。

Action loadPartners is not passed as argument to component helper. Its just static component's action.

所以问题是如何从集成测试中存储动作loadPartners?

So the question is how to stub action loadPartners from integration test?

推荐答案

在集成测试中,不应该更改组件的内部部分。您应该更改组件依赖关系的实现。

In an integration test, you shouldn't change the inner part of components. Instead of it, you should change implementations of your component's dependencies.

所以在这种情况下,你应该存根 store

So in this case, you should stub store. See how to stub store.

参考指南

这篇关于如何在ember中存储组件的动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆