Skip to main content
The 2024 Developer Survey results are live! See the results

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.

14 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
3 votes
0 answers
2k views

LWC - Jest test for Apex calls in wired function

We have a class that calls the getRecord uiAPI and then using the result makes an APEX call to get more details from another custom object. import { LightningElement, api, wire, track } from 'lwc'; ...
raj's user avatar
  • 183
3 votes
0 answers
453 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
  • 335
3 votes
1 answer
234 views

ApexMock FileNotFound Exception

I am trying to learn how to write tests for apex services using ApexMocks framework. I want to generate Mock classes through apex-mocks-generator and I am following simple instructions given in this ...
Faiza Iqbal's user avatar
2 votes
0 answers
782 views

With LWC Jest, how to mock custom components

I'm trying to unit test my LWC which has another custom component as child. I tried to use the steps describe in this post : import { createElement } from 'lwc'; import EfxProjectReport from 'c/...
Ombrelin's user avatar
  • 413
2 votes
0 answers
319 views

Post callout behavior assertions for unit test with static resource callout mock fail

I have a working queueable callout, and working tests using static resource callout mock I can successfuly run basic assertions on the mock response body and status. However, the callout method in ...
gorav's user avatar
  • 4,547
1 vote
0 answers
95 views

Stub API not calling trigger

I am using Apex DML mocking using stub api and got a reference from multiple blogs, https://github.com/packocz/Pragmatic-Bear-Blog https://github.com/Coding-With-The-Force/Salesforce-Development-...
sumit's user avatar
  • 479
1 vote
0 answers
1k views

Proper way to mock svg html template in Jest?

I want to create lwc component which selectively renders svg from html template files. I wonder how to mock that templates for the needs of JEST test. Import the same templates for component and test ...
Grzegorz Połuch's user avatar
1 vote
0 answers
417 views

Is it possible to mock an approval process through Apex?

I have a generic piece of code that is responsible of approve a record. It does not assume the SObject type nor the process definition. For example, something like the following: public static Boolean ...
gvgramazio's user avatar
0 votes
0 answers
149 views

How to use Apex Mockery Lib for simple scenario?

Was wanting to use Stub API for mocking test for some time but had been too busy to try it out. I saw some devs recommending FFLib but I find it too heavy a framework for most SF envs. So looking for ...
compski's user avatar
  • 1,352
0 votes
1 answer
203 views

LWC Jest: test a component that uses lightning/toast

The lightning/toast utility is GA as of Winter '24, but I haven't seen anything on StackExchange or in the docs about how to write tests for components that use it. One you import it into a component ...
Matthew Souther's user avatar
0 votes
1 answer
222 views

How to mock AuthSession in test class

I want to cover this method : @AuraEnabled public static void endUserSession(Id userId){ List<AuthSession> uSessions = [ select Id , UsersId FROM AuthSession WHERE UsersId =:userId AND ...
Fark's user avatar
  • 27
0 votes
0 answers
200 views

How to generate key prefix for "unstable" types

I use a mocking framework that exposes a method for generating mock record ids. The utility method uses getKeyPrefix() to mock an Id. This works for most object types but doesn't work for __Share ...
TemporaryFix's user avatar
  • 2,946
0 votes
0 answers
75 views

Mock Webservice called from a trigger repeats until I get a 'too many callouts: 101' message

I'd really appreciate any suggestions that the group may have. I'm writing a test class for a SalesForce trigger that calls a webservice. The trigger works fine in the Sandbox environment, but ...
djpackman's user avatar
0 votes
0 answers
74 views

Getting INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY when mocking an Object using Stub API

I am mocking a routing rule object by using the JSON list below that has an ID of type Routing_Rule__c. The Test is about creating some rules and setting some flags that would cause the lead object to ...
kratos's user avatar
  • 541