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
0
votes
1 answer

How to spy a function with Sinon.js that is in the same js file as the function under test

I have a problem with Sinon.js while trying to spy a function that is in the same javascript file as the function that I want to test. Furthermore I assert that the spied function is called once. Unfortunately the test fails. Interesting thing is,…
MeBNoah
  • 165
  • 14
0
votes
1 answer

Spying method calls the actual Method

I am writing a JUnit with Mockito. But on the line when(encryptDecryptUtil.getKeyFromKeyStore(any(String.class))).thenReturn(keyMock); It calls the actual method, which is causing the test failure. Interesting point is that it directly makes the…
user3452558
  • 67
  • 2
  • 10
0
votes
1 answer

Jasmine and Spying/Mocking - JavaScript Prototypes

Alrighty so here's the breakdown: I have a file called FileA.js. Within FileA.js I have a prototype FileAObject.prototype, with the associated function funcAlpha(). Thus we have something like this: File = FileA function someFunction() { …
0
votes
0 answers

how do I fix it:

I am implementing an application at the time of test displays the poolside error: Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException:…
Roger
  • 1
  • 1
0
votes
1 answer

Angular - Jasmine: Testing immediately invoked functions inside a directive controller

Suppose that I have a directive like: .directive('myDir', function(TemplateHandler){ return { ... controller: function(ExploreCmd){ this.foo = { bar: function(){...} }; this.foo.bar(); } } }); And I want…
teone
  • 2,153
  • 3
  • 25
  • 49
0
votes
1 answer

Unable to spy on existing function

I'm unable to spy on an existing function in the current scope within node.js: function myFunc() {console.log("Spy on me and I'll have you arrested"}; sinon.spy(myFunc); myFunc.restore(); // throws an error: myFunc.restore is not a function I can…
eye_mew
  • 8,855
  • 7
  • 30
  • 50
0
votes
2 answers

Jasmine not working for link directive on document click

My Directive Link function is given below - link:function(scope,elem,attr){ $(document).on("click",function(event){ var target = $(event.target); if(target.is('.detailBox') ||…
anand patil
  • 507
  • 1
  • 9
  • 26
0
votes
1 answer

Java Mockito - How to test a method which is calling a method in the same class as well as a method from other class?

I have the code structure like this. Method methodToTest in ClassA is calling a method in ClassA as well well as a method in ClassB public class ClassA { @Autowired ClassB classB; public void methodToTest() { Object c =…
msfk
  • 137
  • 1
  • 15
0
votes
3 answers

How to close Object Spy of HP UFT(12.02) using vbscript

We are using UFT for automation testing and have our own framework to invoke the Uft and load the scripts. But if by chance Object spy is open UFT gives an error " the program is waiting for another user.." Can any one help to close object spy ( if…
0
votes
1 answer

How to spy inside stub returns with sinon

Hi I want to spy the function as below, and because the function returns a promise, so I need to return the promise let other code continue running. But it never passes the test, am I doing it wrong? how can I do this correctly? Thank you in…
Sabrina Luo
  • 3,810
  • 4
  • 16
  • 35
0
votes
0 answers

Angular Testing: It's valid testing that an service not to have been called when I test a restricted submit data?

I have this code: angular .module('ExampleApp') .service('MyService', Service); function Service(){ var self = this; self.save = function(_data){ //save the data in the server } } angular .module('ExampleApp') …
0
votes
1 answer

Jasmine's spy doesn't work in image onload event

I am using karma-jasmine and browserify to test Vue component. One method listen on image on load event. But the spy that called in the event handler didn't get the right result. Following snippets shows the error: let spy =…
Holmes Conan
  • 1,208
  • 12
  • 21
0
votes
1 answer

Sinon: spy turning stub

I'm writing integration tests and want to simulate errors in underlying calls. I know how to do it with sandboxing internal calls, but I want to do some blackbox testing without using Sinon's sandbox on internals but on passed parameters. I want my…
Roman Dibikhin
  • 856
  • 4
  • 15
0
votes
1 answer

Spying with Mockito

As per THIS post, There are two ways to mock the method doSomeStuff() to return a 1 : when(bloMock.doSomeStuff()).thenReturn(1); and doReturn(1).when(bloMock).doSomeStuff(); The very important difference is that the first option will actually …
Andy897
  • 6,915
  • 11
  • 51
  • 86
0
votes
1 answer

How to mock variable in directive unit test?

I have created a custom directive and would like to mock out a variable to make the test working. This is part of the unit test: it('should pass on initialvalue', function() { scope.$apply(function() { scope.initial = 2; …
bier hier
  • 20,970
  • 42
  • 97
  • 166