Giter Site home page Giter Site logo

Comments (2)

joseph-ortiz avatar joseph-ortiz commented on July 17, 2024 1

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.

alec-ng avatar alec-ng commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.