Skip to main content

Questions tagged [mock]

Mock classes are used in testing to simulate the responses of real code in a controlled, reproducible fashion. In particular, HTTPCalloutMock and WebServiceMock classes are used to supply response values to callouts made during a unit test.

Filter by
Sorted by
Tagged with
12 votes
3 answers
7k views

LWC + Jest: Mocking imperative Apex and returning a value

I'm going to do a Q&A-style entry here, since I couldn't find anything on the web describing this use case. I have seen several threads here describing how to do an empty mock on an Apex call in ...
Matthew Souther's user avatar
9 votes
2 answers
4k views

Is there a way I can mock an AggregateResult?

I'm trying to write most of my tests without hitting salesforce database. For that I'm implementing some simple mock class where I just return some SOQL queries when needed. The problem I'm facing now ...
Francisco Riccomagno's user avatar
3 votes
2 answers
3k views

Unit Testing External Object with Mocked Data

New to the SF dev world so I am struggling a bit with setting up some unit tests on external objects. I have found very little info on this, most dating back a few years. I did find a post here on SO ...
SBB's user avatar
  • 173
3 votes
1 answer
3k views

How do I mock a child LWC in a parent's Jest Unit Test?

I have two components that are in my app: parentComponent childComponent. 'parentComponent' includes 'childComponent' as a component. E.g: parentComponent.html <template> <c-child-...
Rob Baillie's user avatar
2 votes
1 answer
5k views

How to mock custom LWC components in JEST

I am still new to JavaScript and especially Jest, so apologies in advance for the maybe stupid and uninformed question. To isolate my tests, I want to mock one of my custom table components. In short,...
J. Schreiber's user avatar
  • 1,764
3 votes
0 answers
463 views

Mock a class that implements Schedulable using Stub API

I'm using Stub API (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_stub_api.htm) to mock a class that implements Schedulable and because of this I'm getting an ...
ashkanent's user avatar
  • 355
1 vote
1 answer
2k views

how to mock Object list in a test class?

This is a method in my apex controller class: @AuraEnabled public static void sendMail(List<Object> selectedRows) { if (selectedRows.size() > 0) { for (Object obj : ...
Jayesh Babu's user avatar
1 vote
1 answer
212 views

Problems with callouts Mock and tests

We have a problem in our organization and I was hoping for some advice from you on how to best tackle this. We have a handler class that makes a callout to a Master Data Management system for account ...
Ivar Gunnarsson's user avatar
0 votes
1 answer
1k views

Testing/Mocking design pattern to test Messaging.SendEmailResult

I have some code in an After Insert trigger that does some conditional DML updates to the records being inserted if a mail is successfully sent out. I'm looking for a solid, modular way to test this, ...
Michael Paler's user avatar