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
2
votes
1 answer
spyOn that is being called returns not being called with angular5 unit test
My component has:
export class JsonformComponent implements OnInit {
@Input() dataplanDetails: any;
public layout: any = [];
public schema: any = {};
ngOnInit() {
this.dataplanDetails.subscribe(res => {
return…

Shamoon
- 41,293
- 91
- 306
- 570
2
votes
1 answer
Mocha sinon.spy always showing function call 0 times
I am new to mocha/chai. I am trying to write the unit test case for following scenario. I want to test whether "callchildfunc" and "childfunc2" is called or not upon calling "parent()" function.
I have read the fundamental and what I understood is…

Henry
- 145
- 4
- 14
2
votes
0 answers
Testing ngrx Effects with Jasmine spy
I am writing an ngrx effect and trying to test it. However, the effect calls a service that calls an API that will require authentication. As a result, I am trying to create a spy in Jasmine to handle returning the data. This is my first time using…

ChristyPiffat
- 359
- 1
- 6
- 26
2
votes
1 answer
Jasmine Spy not Returning Correct Value
In my Jasmine test specs, on occasion I spy on authState, a property of my mock service mockAngularFireAuth and return different values representative of the state of the app under that specific test.
In one test this works perfectly and the…

Jonathon Oates
- 2,912
- 3
- 37
- 60
2
votes
2 answers
javaagent not working with javaws and JNLP
I have an agent JAR (jar-with-dependencies) with premain as
public static void premain(String args, Instrumentation instrumentation) {
log.info("Starting Swing Testing Tools");
log.info("Adding global listener using agent");
…

Gagan
- 137
- 1
- 13
2
votes
0 answers
Mockito - spy of parameterized class calls mock method
I have been scratching my head a lot over something which just happened with Mockito.
I have this class, called ExamineFilter, which up to now has not been parameterised. 150+ tests to do with this class and others all passing fine. Lots of…

mike rodent
- 14,126
- 11
- 103
- 157
2
votes
2 answers
How to mock a void method with PowerMockito?
This is a duplicate of this question. There are bunch of similar questions/answers as well but none helped me. As there are hundreds of developers accepted some answers I am probably wrong somewhere and have no idea where is my problem!
This is my…

Hesam
- 52,260
- 74
- 224
- 365
2
votes
3 answers
How to use mockito to not evaluate a method inside the testing method
I am implementing a test case for a controller method. The controller method looks like below,
public class LoginController{
public String register(String token){
//some logic
loginService.delete(String token);
//some logic
…

Anna
- 1,499
- 4
- 13
- 18
2
votes
1 answer
Spying a method is calling the actual method instead of the mocked one
I have a service class say 'HostService'
@Service
class HostService {
@Autowired
private val platformService: PlatformService = null
def views: Option[HostView] = {
val ip = "10.x.x.x"
if…

user2613399
- 715
- 1
- 6
- 14
2
votes
1 answer
Sinon spy for function doesn't work
According to documentation of sinon.js, I can do like this: var spy = sinon.spy(myFunc);, but it doesn't work. Here is my effort:
var sinon = require("sinon");
describe('check bar calling', function(){
it('should call bar once', function() {
…

Rostislav Shtanko
- 704
- 2
- 9
- 30
2
votes
2 answers
Typescript syntax - How to spy on an Ajax request?
I am trying to write a unit test where I want to verify that a ajax call has been made.
The code is simple :
it('test spycall',()=>{
spyOn($,"ajax");
//my method call which in turns use …

TypeScripter
- 879
- 2
- 10
- 23
2
votes
1 answer
Using expectException and a spy in PHPUnit
I'm using PHPUnit ~5.2 and PHP ~7.0.0.
I have a class that wraps a repository, catches the exceptions it throws, calls a logger and then rethrows the exception.
public function storeDonation( Donation $donation ) {
try {
…

Jeroen De Dauw
- 10,321
- 15
- 56
- 79
2
votes
1 answer
Delphi Unit Testing : Writing a simple spy for the CUT
I'm searching for a way to easily and concisely write a spy for the DUnitX testing framework under Delphi.
In the past, I've used very ugly ways of doing that using :
[TestFixture]
Test = class(TObject)
public
[test]
procedure…

Ludovic C
- 2,855
- 20
- 40
2
votes
2 answers
How to unit test that a filter has been called in a service
I am having trouble asserting that my filter has been called after a promise has been returned.
This code is called from a controller which then pulls the data to filter from a http GET service:
getPermissions(){
return…

RyanP13
- 7,413
- 27
- 96
- 166
2
votes
0 answers
How to test if an spy argument is a specific function in sinon.js spy using qunit
How to test if an anonymous function was passed as parameter in a spy function of sinon.js?
Imagine a function like that.
function myFunction(){
//do stuff
otherobj.anotherFunc({myobj: 'value'}, function(){ console.log('test'); });
}
I…

jplindgren
- 298
- 3
- 10