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

using sinon.spy when two methods have the same name but different arguments

I am trying to use sinon.spy() on an object with two methods called draw (both with same name but different arguments) as follows: const spy = sinon.spy(obj,'draw') When I try to test the spy with…
Sabo Boz
  • 1,683
  • 4
  • 13
  • 29
2
votes
0 answers

Jest: spy axios in React

I'm new to Jest (and testing javascript in general). I've got a Register component which is basically a page to register a user. When the form is completed and the submit button is clicked it will use axios to send a POST request to the server. I'm…
MrCujo
  • 1,218
  • 3
  • 31
  • 56
2
votes
0 answers

Proxyquire and Sinon to check if function is called

I'm trying to write a test within a file called fooTest that's trying to check if, in the file foo, when I call fooHandler, a function in the file bar is called. I've been able to test that the function in bar is called. (barSpy = sinon.spy(), and…
user319407
  • 173
  • 1
  • 2
  • 4
2
votes
0 answers

How to get unique jest spy in concurrent tests?

I am mocking a function (react hook) to return something for a unit test, and would like to verify with a spy that it has been called only once. This works fine for regular tests, but when trying to add test.concurrent.each, the spy appears to be…
Adrien Lemaire
  • 1,744
  • 2
  • 20
  • 29
2
votes
3 answers

How to mock property of a service class in angular (Jasmine/Karma)

I am trying to mock currentOrganizationMessageSource from my service but getting getting following error: this.OrganizationService.currentOrganizationMessageSource.subscribe is not a function I tried to use spyOnProperty and than I get…
Mishi
  • 628
  • 4
  • 16
  • 40
2
votes
1 answer

Matplotlib: Transparent spy plot over imshow

I'm trying a create a plot with two types of plots on top of each other: pyplot.spy over pyplot.imshow. Since spy plots a sparse matrix, I want it to be transparent where the matrix has zeros. However, when I plot the sparse matrix on the same axis,…
Karen Chen
  • 21
  • 3
2
votes
1 answer

In JUnit with Mockito, how can I wait for an asynchronous method to complete?

I am writing an integration test against some code that asynchronously creates a record when a different value is updated in the database. I would like to check the state of the system after the record is created, verifying that it was created as…
M. Justin
  • 14,487
  • 7
  • 91
  • 130
2
votes
0 answers

Problem discovering control handles \ spy++

I use SPY++ to find out control handles, usually it works, it seems that on some application it doesn't work. For example, on the calc.exe in WIN7 i can find out each digit control handle (and simulate a press on it), in WIN10 calc, i cannot find…
vila
  • 21
  • 1
2
votes
2 answers

Spy a service spring having transactional methods

I am trying to write some JUnit tests. In my test class i need to spy a service having transactional methods in the implementation. When i am trying to spy that service, i get this error: Mockito cannot mock/spy because : - final class If i…
2
votes
0 answers

Dart Mockito: spies?

I don't see any mentions of spies support in Mockito for dart in the latest versions. In the changelog: 2.0.0-dev # Remove export of spy and any dart:mirrors based API from mockito.dart. Users may import as package:mockito/mirrors.dart going…
nyarian
  • 4,085
  • 1
  • 19
  • 51
2
votes
2 answers

Why I get NullPointerException while mocking?

Why do I get NullPointerException? Here is my code: @Stateless @LocalBean class SomeDao { @PersistenceContext(unitName = "some-value") private EntityManager entityManager; public EntityManager getEntityManager() { return…
pityo10000
  • 117
  • 1
  • 13
2
votes
1 answer

Unit test component with mocked service - error

I started working on testing components and service in Angular. I watched a course on pluralsight and tried to follow ideas from: https://codecraft.tv/courses/angular/unit-testing/mocks-and-spies/ however, I have a problem with the testing…
korn
  • 65
  • 1
  • 6
2
votes
1 answer

unit testing observables with createSpyObj

I have a function that calls another that itself uses a http subscription, and I am having trouble testing it... MyComponent id = 1; myFunct() { this.myService.delete(this.id); } MyService delete(id) { this.http.delete(this.myUrl + '/' +…
physicsboy
  • 5,656
  • 17
  • 70
  • 119
2
votes
1 answer

Spark : Scala mocking, Task not serializable

I am trying to use mockito for unit testing some scala code. I want to run spark locally, i.e. in my IntelliJ IDE. Here is a sample class MyScalaSparkTests extends FunSuite with BeforeAndAfter with MockitoSugar with java.io.Serializable{ val…
AbtPst
  • 7,778
  • 17
  • 91
  • 172
2
votes
3 answers

Mockito not mocking private variables using @Spy

I am attempting to mock a private instance variable listOfStrings using Mockito's @Spy annotation. @RunWith(MockitoJUnitRunner.class) public class MyObjectTest { @InjectMocks MyObject myObject; @Spy List listOfStrings; @Before …
Adrian Elder
  • 1,993
  • 3
  • 19
  • 38