Category "mocking"

How to mock only one typescript class from a module, but leave other classes/functions as is, using the jest framework

I have a typescript module with a function that I'm trying to test with jest. The function I'm trying to test uses a typescript class that's defined in the same

How to mock a 'request' node module for testing in jest

I am new to writing test cases in jest and i wanted to test 'mark' function and want to mock 'request' node module. let's say this file's name is app.js and tes

Im not able to mock ServiceBusReceivedMessage and ServiceBusMessageActions

we want to write unit-test for servicebus message trigger. we are using Azure.Messaging.ServiceBus nuget package [FunctionName("serviebustrigger")] publi

how to mock slack web api for jest

i have an app that's using the @slack/web-api package through the named import WebClient. i want to test one of the controllers that uses a model that in turns

How to mock method of a mocked class

Changed the titel to a more common one. I guess the problem is not that class specific. I want to mock google.cloud.pubsub_v1.SubscriberClient I want to set a f

Is there a way to mock Random.Next regardless of what gets passed to it and where it gets called?

I have the following method I wish to unit test: public class Board { public static BoardElement RandomElement(List<BoardElement> elements) {

Mocking federated modules in host application for jest

Question is exactly same here in fact but has different context: How to mock not installed npm package in jest? I am part of a project where new Module Federati

Mock smart contract solidity - can't deploy mock smart contract - TypeError: Contract "mockMyToken" should be marked as abstract

I wrote a smart contract that uses openzepplin ERC20 standard. I am able to deploy it using truffle and my tests work as expected. I am now trying to test part

Why can't dunder/magic methods be set in unittest.mock.Mock.configure_mock?

I was writing some unit test in python and needed to mock a very general collections.abc.Sized, so I set off creating a Mock with a __len__ method whose return

Why is my resetAllMocks not working in jest

The second expect(fs.writeFile).toHaveBeenCalledTimes(1) (in describe('Guid for MPX') returns an error because the writeFile has been called twice. In theory, j

How to use mocks in tests with Adonis 5 (adonisjs/fold package)?

I have an API built with Adonis 5 (core version 5.4.0). The tests are made with Adonis' own runner, japa (version 3.1.1). As per the Adonis documentation, I bui

Custom data type wtih Mockaroo

I am trying to generate mock data with Mockaroo and need a simple data type that is unfortunately not inside Mockaroo's built in available data. It is very simp

How can I mock dependencies which aren't interfaces but subclasses?

I'm not sure if my design is simply stupid, or there's a good way to make it work. Consider the following classes: public abstract class CheckBase { protect

How do I mock a static void method (not with doNothing or invocation -> null) using Mockito.mockedStatic?

I have the following classes class FileDownloader { public static void downloadFile(String repoUrl, String filename) throws IOException { // Downloa

Mock patch specific instance of class

How to mock a specific instance of a class using patch? In my test file I have: @classmethod def setUpClass(cls): cls.instance_of_my_class = myClass() one

error when Add a stub for a method using Mockito's 'when' API

Have this abstract class to get data from remote data source abstract class NumberTriviaRemoteDataSource { /// Calls the http://numberapi.com/{number} endpoin

What is the best practice to Mock the whole API

Input: We have API-A and API-B. API-A sends some requests to API-B and do some work with received data. We have unit tests that verify work of methods that doin

How do I mock boto3's StreamingBody object for processing with BytesIO in Python?

I'm unittesting a function that transforms an element from an S3 object into a pandas DataFrame and need to mock the returned StreamingBody object from boto3 f

Trying to mock an http client that is inside a controller, using phpunit, but it doesn't work

I have to test the routes of a controller which uses Guzzle Wrapper as a client to get data from an API. The app uses Laravel as a framework. This is the part o

How do I mock a function with no parameters that sets a class attribute for Python unit tests?

My class, Foo, has a calculate method that takes no parameters, makes a call to a database and does some calculations using class attributes, and sets another c