Questions tagged [spy]

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

425 questions
2
votes
1 answer

Angularjs unit testing resolving promises

I'm probably doing this wrong but I can't figure out how to fix it. I want to test a controller that uses a resource (ngResource) and I want to use a Spy as a test double for the resource so it doesn't actually do the http call. In the code below I…
Victor P
  • 1,496
  • 17
  • 29
2
votes
1 answer

Javascript Jasmine Testing: Prevent tested function to call function from object that was created within tested function

I want to test a Javascript function with Jasmine that has a structure like this: showEditUser: function (...) { // more code here... var editUserView = new EditUserView(); // more code here... …
Garrarufa
  • 1,145
  • 1
  • 12
  • 29
2
votes
2 answers

How does a Mockito spy know when it is spying?

This code from the documentation is totally baffling me: List list = new LinkedList(); List spy = spy(list); when(spy.size()).thenReturn(100); // <--- how does this spy know // not to call the real method???? //using the spy calls *real*…
djechlin
  • 59,258
  • 35
  • 162
  • 290
2
votes
1 answer

Changing fields of a mockito spy

So lets say I have a class class JustAClass() { Stirng justAField = "nothing"; } Now I'm testing this class and I put it into a mock JustAClass realClass = newJustACLass(); JustAClass spyClass = Mockito.spy(realClass); spyClass.justAField =…
Anton
  • 2,282
  • 26
  • 43
2
votes
1 answer

jasmine spyOn not reporting correctly for toHaveBeenCalled and toHaveBeenCalledWith

Code under test: module lib { export class Topic { private _callbacks: JQueryCallback; public id: string; public publish: any; public subscribe: any; public unsubscribe: any; public test: any; …
Mike
  • 1,405
  • 1
  • 17
  • 27
2
votes
1 answer

Spying on Backbone View callback method with Jasmine

I have the following view: ... var TreeView = Backbone.View.extend({ el: '#org-tree', initialize: function() { eventBus.on("route:change", _.bind(this.triggerFilterEvent, this)); }, render: function() { ... }, foo:…
Will
  • 2,858
  • 6
  • 33
  • 50
2
votes
1 answer

Is mockito changing the objects?

I have the following structure public class A{...} public class B extends A{ private C cObject; private Object otherValue; B(){ cObject = new C(this); } } public class C{ private B bObject; C(B bObject){ …
iberbeu
  • 15,295
  • 5
  • 27
  • 48
1
vote
1 answer

How to spy on interceptor class with mockito in quarkus test

In unit test I try to spy on following intceptor class, on method org.acme.LoggingInterceptor#log(java.lang.String) package org.acme; import javax.enterprise.context.ApplicationScoped; import javax.interceptor.AroundInvoke; import…
syr
  • 836
  • 1
  • 12
  • 28
1
vote
0 answers

Vue: How to test function within another function with Vitest

So I have this function inside my Vue Component: function openLink(event: Event, url: string, type: string) { switch (type) { case 'onetype': case 'twotype': event.preventDefault() openURLInBrowser(url, '_blank'); break …
mikasa
  • 105
  • 1
  • 8
1
vote
0 answers

Jest spy toHaveBeenCalled not seeing function as being hit

I am unit testing my JS file which consists of a lot of exported consts, with one of the functions calling some of the others held within the file, however I can't seem to get my test to see that it has done these calls - even though running the…
physicsboy
  • 5,656
  • 17
  • 70
  • 119
1
vote
2 answers

cypreess to get browser logs for specific page

I have been working on a Cypress project for 2 months. My next task is to get the browser logs. Let's imagine this page is the one I need to test for the moment:
yasith rangana
  • 196
  • 2
  • 12
1
vote
1 answer

Spy with mockito a class extending ArrayBlockingQueue

Hello anyone would know how to spy a class that is extending ArrayBlockingQueue? For example I want to spy the following MyBufferQueue class public class MyBufferQueue extends ArrayBlockingQueue {} Inside of ArrayBlockingQueue class that…
1
vote
1 answer

Getting exception as, Argument(s) are different! Wanted:

@Spy @InjectMocks NotificationServiceImpl notificationService; When i use like above, I am getting exception for a test as, Argument(s) are different! Wanted: But but while debugging control is going inside all methods and code coverage is…
gan7202
  • 41
  • 6
1
vote
1 answer

Cypress spy method on page component

What I'm trying to do here is simple : I have and filter method called "search()" that is called on different action on my page. I'd like to "spy" this method and then check if it was called with : cy.get('method').should('be.called') But really, I…
Jérome BORGA
  • 555
  • 1
  • 3
  • 12
1
vote
0 answers

Are spies a bad practice when we are unit testing?

When we have a situation where the method has no return and its behavior is just calling a dependency according to the input as in the example below, is it bad practice to use spies? Would it be correct to refactor the method to make it return…
Gnu
  • 23
  • 3