lundi 9 janvier 2017

Unit test ember component

I have a single action defined in an ember controller that calls 2 separate functions that are part of the controller. I'd like to mock out those functions in a unit test in order to confirm if the action method called the correct function.

My controller looks like this:

export default Ember.Controller.extend({
    functionA() {
        return;
    },
    functionB() {
        return;
    },
    actions: {
        actionMethod(param) {
            if(param) {
                return this.functionA();
            }
            else {
                return this.functionB();
            }
         }
    }
});

My unit test looks like below -

const functionA = function() { return; }
const functionB = function() { return; }
test('it can do something', function(assert) {
    let controller = this.subject();

    controller.set('functionA', functionA);
    controller.set('functionB', functionB);
    controller.send('actionMethod', '');

}




Aucun commentaire:

Enregistrer un commentaire