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
11 votes
3 answers

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

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
2 votes
1 answer

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,520
2 votes
1 answer

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
3 votes
1 answer

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
0 answers

Mock a class that implements Schedulable using Stub API

I'm using Stub API ( to mock a class that implements Schedulable and because of this I'm getting an ...
ashkanent's user avatar
  • 335
1 vote
1 answer

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

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

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