mercredi 3 février 2016

Jasmine spyOn on function and returned object

I'm using MeteorJS with angular and want to test controller. My controller use $reactive(this).attach($scope). I need to check, if this method was called.

I create something like that for spy:

var $reactive = function(ctrl) {
    return {
        attach:function(scope) {}
    }
};

So I can call it like that:

$reactive('aaa').attach('bbb');

How I can do it in tests?

spyOn($reactive, 'attach');

Doesn't work. I got Error: attach() method does not exist

And how to check if it was called? This is good call?

expect($reactive).toHaveBeenCalledWith(controller);

And how to check that function attach was called with args (scope)?

Aucun commentaire:

Enregistrer un commentaire