A spy is XUnit pattern where you replace the original implementation with a test double to capture the calls on the object. Later in your test you can verify the object under test has made specific calls on that object
Questions tagged [spy]
425 questions
7
votes
1 answer
Jest/React mock scrollBy and .getBoundingClientRect function
I have a function handleClick which uses scrollBy on an element which gets its first argument using getBoundingClientRect. I am trying to test this using jest/enzyme.
class myClass extends Component {
...
...
handleClick () {
…

Mohammed
- 555
- 1
- 6
- 19
7
votes
1 answer
Testing FileSaver in Angular 5
I have imported file-saver in angular 5 application, when I am executing test cases it is giving following error:
TypeError: FileSaver.saveAs is not a function
Spec.ts:
import FileSaver from 'file-saver';
.ts
import FileSaver from…

Sreekanth Reddy
- 483
- 1
- 6
- 17
7
votes
0 answers
Mocking an environment in Angular with Jasmine
I'm still learning how to write tests for angular using Karma/Jasmine. I want to return false for the environment's isDebugMode. It works obviously when I change the code for it but how do I write a test for that? I have set up some tests trying…

classic89
- 81
- 1
- 4
7
votes
3 answers
Capturing Win32 messages
Does anyone know a tool that can capture win32 messages that get sent to a particular process? I thought there was a tool from sysinternals for that but now I can't locate it. Anyone knows some?

Peter Krumins
- 838
- 1
- 7
- 24
7
votes
1 answer
Spy utility for Windows 8
I've used Snoop, it is the brilliant tool for WPF. SilverlightSpy has similar functionality for Silverlight and WP7. Does anybody know about any similar tools for Windows 8 projects?
EDIT : I mean Windows Metro style applications on C#/XAML that run…

RredCat
- 5,259
- 5
- 60
- 100
6
votes
1 answer
How to properly spy on an input stream
My understanding is, that Mockito.spy(object) wraps a proxy around an existing object. This proxy delegates the method calls to the spied object and allows further verification (So it's different to a mock which provides no implementation).
I want…

swaechter
- 1,357
- 3
- 22
- 46
6
votes
1 answer
Vue3- Using Vitest toHaveBeenCalled() method
I am running a vue3 application using the Composition API and the setup() hook.
I am using Vitest as unit-test framework. (v 0.6.1)
I have the following sample component :
// src/components/MyComponent.vue
counter : {{…

Deltantoine
- 61
- 1
- 2
6
votes
2 answers
Why isn't jest's clearAllMocks working and how do I clear mocks for jest spies?
I'm using jest 4.2.4 with my React 16.13.0 application. I have set up this type of mock ...
jest.spyOn(ReduxFirebase, "getFirebase").mockReturnValue({
firestore: jest.fn(() => ({ collection: jest.fn(() => collection) })),
});
How do I…

Dave
- 15,639
- 133
- 442
- 830
6
votes
1 answer
Spy an object with Moq (C#)
I am building a .NET Core application and I want to spy on an instantiated object using Moq, but I have not found a way to do it.
Basically, what I need is what is described here as spying.
I have found that I can call the base class methods of a…

orestis
- 932
- 2
- 9
- 23
6
votes
0 answers
How to mock individual methods of a SpyBean?
I'm working on a test class where one specific test needs the actual implementation of a method of a service class that I'm mocking. So I thought, why not use @SpyBean instead of @MockBean and use the actual implementation where I need it (don't…

DanDan
- 1,038
- 4
- 15
- 28
6
votes
2 answers
How Can you Use a DebuggerTo Step through a Mockito Spy Object?
I would like to be able to step through a debugger, in particular Eclipse, on a Mockito Spy object. As an example, say I have the class to test below:
public class someClass(){
public someMethod(){
System.out.println("Begin someMethod…

Michael Rountree
- 175
- 2
- 12
6
votes
1 answer
Trying to spy (Jasmine) on Array.prototype methods causes stack overflow
This is pretty odd. Using the testem runner with jasmine2 and the following spec executes (though it correctly flags that there are no expectations):
describe('Spying on array.prototype methods', function(){
it('should work this way', function(){
…

Gabriel L.
- 1,629
- 1
- 17
- 18
6
votes
1 answer
How can I spy on a mock service AngularJS / Karma?
'use strict'
webApp.controller 'NavigationController', [
'$scope'
'$rootScope'
'UserService'
($scope, $rootScope, UserService) ->
$scope.init = ->
UserService.isAuthenticated().then (authenticated) ->
…

Shamoon
- 41,293
- 91
- 306
- 570
6
votes
3 answers
Mockito spy method not working
I'm in trouble with mockito.spy method.
I'm recently arrived on a "old" project and my first task is to add mockito in it, and to do real unit test :)
the project has many conception problems but its not the point here ;)
I explain my problem:
I…

Mançaux Pierre-Alexandre
- 858
- 1
- 11
- 42
6
votes
3 answers
How do you spy on AngularJS's $timeout with Jasmine?
I am trying to spy on $timeout so that I can verify that it has not been called. Specifically, my production code (see below) calls $timeout as a function, not an object:
$timeout(function() { ... })
and not
$timeout.cancel() // for…

Yngvar Kristiansen
- 1,453
- 1
- 18
- 25