6

I have a Lightning Component that uses the lightning:workspaceAPI component to detect that it is (or is not) running in the console view. I'm starting to look at setting up some Lightning Testing Service (LTS) tests and am wondering what can be done to either mock or configure so that the lightning:workspaceAPI calls work?

In general I haven't found too much information beyond the very simple tests included in LTS itself. And this question What to Javascript-test in Lightning components and what not here on this site.

PS

I've posted this question here https://github.com/forcedotcom/LightningTestingService/issues/52 as the closed issue list has a number of questions that have been answered.

3
+50

I posted a reply with a couple of options for you to evaluate at, https://github.com/forcedotcom/LightningTestingService/issues/52

Edit: Copied below by Keith C as generally link-only posts are discouraged here.

I suppose there are 2 approaches you can evaluate,

1) Try using mocking capabilities of the Test Framework. This is probably more practical as it doesn't require you change existing code. For example,

  • Jasmine has some out of the box support via 'spyOn' which is also being used here by jasmine example.
  • In case of mocha, LTS brings in sinonjs for mocking/spying which is being used here in a mocha example.

This thread also has some discussion about jasmine spies.

In your case, I am thinking that you would spy on find(),
spyOn(component, "find").and.callFake(function(cId) {..});
to return some sort of proxy/mock.

2) Restructure/Reorganize the components for Dependency Injection where the leaf/UI components mostly act based on information provided to them by a wrapper/container, improving their testability.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.