Closed rsoesemann closed 7 years ago
Jasmine's spies should work for actions enqueued as part of init. Just move the spy call higher up.
From Jasmine's doc "A spy only exists in the describe or it block in which it is defined"
For example, it(...., function(done){ spyOn.... $T.createComponent...... });
One side note: Aura team has a work-item to expose a method like action.getName(), which could be useful in making it easy for the spy to distinguish between if there happen to be multiple actions being enqueued (currently action has other platform exposed methods like getParam() which could be useful).
Hey @esalman-sfdc I can see getName() already working! Alternatively one can overwrite the spy, taken from StackOverflow:
$A.enqueueAction = jasmine.createSpy().and.callFake(function(action) {
console.log(action.getParams());
});
I am trying to test a component with server actions call during
doInit()
. This is my spec:I am testing a component where doInit() uses Promises:
to call 2 helper methods which call server actions
I get obscure JS errors, so I thought maybe this is not the right way to do it. Can you provide an example on how to mock/stub initialisation?