Mocking Questions
Ad
Mocking method results
I'm trying to find a way to fake the result of a method called from within another method. i have a "loaddata" method which calls a
How can I mock/fake/stub sealed OracleException with no public constructor?
In my tests i need to test what happens when an oracleexception is thrown (due to a stored procedure failure). i am trying to setup rhino mocks
Set Pytest mock value to None
I have a main.py file which includes windomgr class, xvfb as a class attibute and two
Mock all except one function in a module
I am testing filea.js, which requires fileb.js in filea.test.js, i wish to mock all methods from
How can I write a unit test for a controller class that uses winforms for views?
Has anyone been able to successfully unit test methods that are, by necessity, coupled to the system.windows.forms.form class? i've
How to create mock model in laravel testing
I need to test a function in usercontroller : public function createuser(request $request): response { $user
Jest - Mocking and testing the node.js filesystem
I have created a function which basically loops over an array and create files. i'm starting to get into testing using jest to have some extra
How to properly mock a function that is imported in a package?
I try to test a package that i created and for that i need to mock subprocess.popen. i want to do this with the patch decorator but i can't
async-aware mock/override environment variables?
Is there an async-aware way to mock environment variables? what i want is a context manager that lets me mock the code inside the
Database entry not saved during unit tests when mocked request
$post= factory(model)->make(); $this->post(route("post.store", $post->toarray()))->assertsee($model->name);
Ad
Python:How to implement multiple dynamic mock.patch functions?
I am trying to dynamically mock/patch multiple @property methods of a class in python i.e. class dog(): ... @property
How to add unit test for a function that calls a function received in props
onsubmit = (e) => { e.preventdefault() const errors = this.validateform() if (!errors) { const { handlesubmit } =
How to "mock" Sentry client in the PHPUnit tests
In case if you need to test php application error handlers, you have to "mock" or just disable sending errors on remote servers in the sentry
Laravel: how to mock dependency injection class methods
I'm using the github api through a
Mocking stripe class from stripe php package in laravel
I'm using this package for stripe
Jest method-invocation count is wrong?
Consider code - // utils.js export const foo = async (a, b) => { // do something bar(a) } export const bar = async (a)
How to mock npm module with sinon/mocha
I'm trying to test a function that calls the module cors. i want to test that cors would be called. for that, i'd have
What's benefits of nodejs mock module like nock?
I develop a nodejs app which get url and send a response (json or xml) depending on parameters in url (i've to develop post and get/post with
Make partial mock of class with Jest in NodeJS
I'm new to nodejs and came from php, where creating partial mock was easy. but i'm not able to accomplish the same with jest in nodejs. i
Trying to mock a DLL in a python wrapper unittest
The problem i'm writing a wrapper for a dll in python, as it gets more complex i'd like to have a few simple unittests that check if the
Jest mocking a function within another function
I have searched quite a bit, and whilst there are many questions asked about mocking functions, none of the solutions i've found work for my
Ad
How to spy/mock minimatch with jest
I am aware of how to mock/spy an es6 import
Mock Bing Maps API with Jest in React.js
In my jest test i need to generate a bing maps push pin like this: it('...', () => { var e = new
How to mock libraries that are unknown in Javascript on my local environment?
I am developing a website using javascript for a device which has a particular javascript library that can be used. this javascript library is
Jest `resetModules()` is breaking `react-router-dom` Context
I'm testing a component which contains the
pytest assert_called_with doesn't work with Django management commands
Django management command: my_custom_command.py from django.core.management.base import basecommand
Mock: assert mock_calls with a numpy array as argument raises ValueError and np.testing.assert_array_equal does not work
I have a mocked object that i would like to check its calls using mock_calls, where it is called with numpy arrays. but the
javascript - how to mock timezone?
I have a function that calculates which date (yyyy-mm-dd) a given timestamp resolves to on the users local timezone. e.g.:
Mock an external endpoint in NodeJs by Moxios
I am trying to mock an external endpoint of twilio in the unit test by moxios library. i am also using
MockWebServer - Value counts differ; Expected: 1, Actual: 0
Logcat error: feb 07, 2019 10:52:49 am okhttp3.mockwebserver.mockwebserver$2 execute info:
type 'Null' is not a subtype of type 'Future<Response>' when testing mocked http client with Mocktail
I have written a test for a simple http get using mocktail to mock the http client. when i call the get method in the test i receive "type
How mock the model without connection database in Laravel
I try to test the method index() of the controller. in this method, there's a model. class usercontroller extends
Ad
Python Patch/Mock class method but still call original method
I want to use patch to record all function calls made to a function in a class for a unittest, but need the original function to still run as
Python mock vs unittest.mock patch
What is the difference between these imports? from mock import patch vs from unittest.mock
Mock module function with jest/enzyme
Following that answer: jest -- mock a
Requestly chrome extension mock api response to 503
I want to change http status code to 503 with a custom response body on url ending with .mpd. i am using
How to test nulls using mockito?
I am using mockito 4.1.3 , and here i have some test class:
Mockk Missing calls inside every { ... } block
I'm stuck trying to mock some stuff with mockk: i have the following setup on gradle root: |-- app (just a sample app
Testing preConfirm hook of SweetAlert2 in a React module
Having a react module name modal as such: import withreactcontent from 'sweetalert2-react-content' export const
Test class within node.js, mock requests
I have following class: class queuerequest{ constructor(){ this.queue = []; } async
Mocking API call in JS
I need to mock api calls for a button click but the actual call is nested down in a utility file that is called by a middleware file. some
Using node to proxy external traffic from container through other service mock the response
I have a node application which i want to write integration tests for. for that to work i need to be able to mock requests for both http requests
How to mock other class functions in testing controller in Laravel
I am trying to test a controller in laravel that uses another class as a helper which calls an api and returns the result. to avoid
Ad
Jest - Mock Response.headers.get()
I have a method which extracts the filename from a http response header: export const getfilenamefromresponse = response => {
assert_called_with failing with empty error message
I am trying to learn python's testing tools and have set up what i though would be a very simple use of @patch(). i have
Move common mocking code to a separate file containing a Jest manual mock
There is a mock i use in many places, so i want to move it into a separate file that can be reused. i think jest calls this a "manual
How to correctly mock i18n for Jest
I have a container in react-native that is importing the typical kind of function that we usually store at utils directory such as
How do I mock express.Application with Jest?
Some class that takes express as an argument (basic di): class app { constructor(express: express.application) { /* ... */ } }
Jest: Find out if current module is mocked during runtime
Is there a way i can find out during runtime if a module is mocked via jest? since mocked modules get required normally and therefore the
Possible to mock model method output in Laravel / PHPUnit?
Is it possible to mock or fake the output of a model method in laravel 5.8? for example, consider this model class website
use mock server in testing flask app using pytest
Tl;dr i am looking for the best practice for testing a flask app which uses external apis under its routes, and probably this is
Node.js - Mock result of a promise
I want to mock the result of a function within a node module so that i can run assertions. considering the following node module:
Sinon - How to make a function thats called indirectly return something
I have been struggling on how i can mock a function so that i can return a fake value from that function. i have a simple script that can
Node.js - How to test HTTPS requests with promise
I started writing unit tests for my nodejs application so i could learn about this concept. after writing some basic tests for simple functions
Ad
Error in .tsx React component when debugging typescript tests using ts-jest
I'm trying to debug my typescript tests in a react app, using ts-jest. my project was generated with
How to replace a class?
I am writing test files for a python module class a: def func(self): b().sub_func() class b: def sub_func(self):
Best practices for using sinon for nodeJS unit testing
I'm coming from java experience with spring framework and looking for the most elegant way to write tests with mocks in nodejs. for java
How do you mock a class function in componentDidMount
Class myclass extends react.component { async componentdidmount(){ const xyz = helperclass.queryparameters('parameter')
How to mock init of helper class
I am having trouble with checking if an object is being constructed with the proper params from another instance of an object. in the below
Do mock files get bundled in the build?
I'm using create-react-app. to test react components i'm using jest and with that mock files. i place the test file
Jest mocks in test util
I'm using a __mocks__ folder to mock a node_module. nice. example to one of the mocks, that mock 'react-relay':
Mock a date in jest not working in different environment
So i trying to mock a date in my test, this is what i did : const mockdate = new date('2018-01-01'); const backupdate = date;
Python mocking elasticsearch connection generator `with` statement
I would like to test a class with a function that has with statement in it: func_to_test(): .... with
Mocking specific reading file error for tests in Node.js
Is it possible to mock, let's say, with the "mock-fs" library some
Python mocking: Patching Python Pika's "basic_publish" function
Consider this code under test: import pika class mq_client(): connection = none channel = none
Ad
Mocking animation completion callback in jest
I'm trying to write a unit test with jest for a reactcomponent that utilises transition from
How to mock Material-UI withWidth HOC
Suppose i have a component which is wrapped in material-ui's withwidth hoc. how do you mock withwidth's iswidthup function using jest to return a
How to mock a File as a prop in jest?
I'm busy getting into unit testing with react, jest and enzyme. i've got a component that takes a pdf file as a prop, see
Pytest mock global variable in subprocess.call()
A global variable can be easily mocked following
Mockiito wrong return value?
Hello i have 2 tests for newinstance() method fragment. but it looks like i'm doing something wrong, because mockito is ignoring my
With Sinon, how can I mocked http.foo.get when http is a property?
I have a file i wish to test, with an http-client that should be mocked: schema.js: const { http
How to mock a koin injected bean in android activity test and capture lambda given as parameter of this mock?
I spent many time to find a smart way to mock koin bean in android activity. unfortunatly none was satisfying ... until the koin-1.0.0-alpha22
Mock new Function() with Jest
I'm having trouble trying to mock a module with a constructor // code.js const serviceclass = require('service-library'); const
Can't find an appropriate mock-server to provide json responses with a predefined url
Well the problem is the following: i'm developing a frontend app (using vue.js), i've to look for a mock backend (i must not mock it on
Why can't I properly stub the twilio library with sinon?
In my code, i have: function handlemessage() { const twilio = require('twilio')(process.env.twilio_account_sid,
Mock an axios request to external service in test
I'm trying to mock a call to an external service from nodejs express. i can't get axios-mock-adapter to intercept the actual axios call
Ad
Not able to mock a method
I have this code i want to test in isolation in some_module.py import tarfile def function_to_test(path_to_tar): tar_file =
Spy on imported function
I want to spy on a function that is executed as soon as the file is required. in the example below i want to spy on bar. i have the following
Mock out a local python variable
Let's say i have the following class: class person: def __init__(self, name): self.name = name def
How to mock a constant that is instantiated outside a function?
I have a constant that is instantiated outside a function, and i wish to unit test that function. but i don't want to update my unit test result
How to mock Express response object in Node tests using Mocha
I need to test a function that requires the response as argument, i'm using mocha and sequelize in node environment with express framework. my
Jest Asynchronous API Mocking
I have searched this issue on stack-overflow, but couldn't find anything similar to me use case. i have container component like this.
How to mock a Python class to return unique autospec Mock instance, every time the class is instantiated?
I am writing a program which creates a subprocess.popen pipeline. i'm trying to mock subprocess.popen such that each
Mocking firebase's auth as object and function at the same time?
I am trying to write minimalistic mocks fro firebase's auth to satisfy use cases like facebooksignin = async () => { try
Laravel testing. Reset controller DI while test
I have a laravel controller with di in __construct(model1 $m1, model2 $m2, $someservice $s) { $this->m1 = $m1; $this->m2
How to mock after setup dagger-android 2.15 when writing espresso tests?
If we just use plain dagger 2. in the application class, we will have a property which holds the appcomponent. then we
How to mock dispatch methods in ReduxAction from flutter package `async_redux`
I am developing an android / ios application in flutter, and i have chosen to use redux for my state management. i am writing unit tests
Ad
Jest Mocking promise not working with error Cannot read property 'then' of undefined in ExpressJS
I am trying to implement a test for my expressjs app. i could not find any solution after googling, please help and save my day...! error
Typescript and Jest: Avoiding type errors on mocked functions
When wanting to mock external modules with jest, we can use the jest.mock() method to auto-mock functions on a module. we
stringContains argument matching within Laravel Log facade shouldReceive
I saw in the laravel docs that it's possible to set a
Javascript Test - Verify if Authorization header is correct using axios
I'm using an axios interceptor to set the authorization token in requests headers. axios.interceptors.request.use(config => {
JavaScript: setTimeOut inside another setTimeOut (nested setTimeOut) to stimulate the API response not working
Requirement: user continuously scans the job numbers in a textbox without any delay. for each jobnumber i need to call an api in
How to mock in-place arithmetic operators
I'm trying to mock the in-place operators' magic methods like __iadd__ with magicmock from unittest.mock,
JS Jest Mocking - expected received undefined error
I have code that uses axios to get some data. const axios = require('axios'); class users { static async all()
How to mock datetime in just one file?
I have two files in which i use datetime. is there a way to mock it in just one file and not the other? following is an example of
How to mock required files in Node.js?
I'm trying to mock a node module so that it will return mocked data. however in my tests it is still making an actual call. considering the
Pytest: mocking / monkey patching builtin input() and print() functions in python
How can i monkey patch the builtin input and print functions using pytest so as to capture the output of someone else's
AppSync GraphQL Mocking Resolver Map Not Generating Unique Items
My mock is not generating unique data for each item, rather each items have the same field value. option 1: (ideal
Ad
patch django.conf settings does not mutate the value
I have vouchered_people in the base.py and i need to test it by dummy i have read
Sinon: How to return based on actual arguments being sent?
Let's say we have a function with two arguments. it's being called many times with different arguments on every call. so, its impossible to stub
Ad
Blog Categories
Ad