Comments (2)
i was in a similar situation testing 3 server calls but I had to make three server calls made in the same component and accomplished it by using action.getName() in the spyOn() callback and branch the response based on the action name.
Note: it does add branching logic to your test which can make your code more complex. Still kind of a newbie at Jasmine so I'm not sure if writing your test like this a good practice or not.
spyOn($A, "enqueueAction").and.callFake(function (action) {
var res = {
getState: function () {
return "SUCCESS";
}
};
var cb = action.getCallback("SUCCESS");
if (action.getName() == 'loadAccount') {
res.getReturnValue = function () {
return [{
"Name": "Acct 1",
}];
}
} else if (action.getName() == 'loadOrder') {
res.getReturnValue = function () {
return [{
"Name": "Order 1",
}];
}
};
cb.fn.apply(cb.s, [res]);
});
from lightningtestingservice.
I think your use case will need to use spyOn(f).and.returnValues()
https://jasmine.github.io/2.4/introduction.html#section-Spies:_%3Ccode%3Eand.returnValues%3C/code%3E
I haven't tried this myself, but the idea is to define n number of return values equivalent to the number of callouts your method will do. If you have 3 server calls when your component initializes, you would define three separate return values (in the order you would expect the callouts to be in).
from lightningtestingservice.
Related Issues (20)
- test an init function
- how to tests when v.body is set HOT 7
- Question on `sfdx force:lightning:test:install -t jasmine` HOT 2
- prerequisites to write tests? HOT 1
- GAC when testing scenario 2 HOT 3
- Testing with namespaces and Labels HOT 1
- jasmineTests.app not working HOT 5
- Setting DateTime attribute using $T.createComponent gives internal server error HOT 3
- Reporting does not escape every attribute in Junit format.
- jasmineTests.app Failed - Definition does not exist HOT 4
- Test reporter not escaping results
- How to test component events when event and handler are in different components?
- Mocking the internal clock in jasmine
- LTS for blur component event HOT 1
- Request: Support JEST HOT 1
- Unable to install LTS with SFDX HOT 4
- lightning:test:run execution permission denied HOT 2
- Fails On Page Load w/ "Freeze Javascript Prototype" Enabled HOT 3
- Installing with sfdx causes a GACK HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightningtestingservice.