Questions tagged [spyon]

116 questions
1
vote
1 answer

Angular2 Unit Testing SpyOn with Karma and Jasmin

I'm facing some weird issue with a test suite I set up. Template : HomeComponent : export class HomeComponent { public test: boolean; public constructor () { this.test = false; } public…
kfa
  • 2,106
  • 4
  • 17
  • 22
1
vote
1 answer

Using Jasmine to `spyOn` a function in a (different) closure

We're using require and Browserify, so single-function modules are imported like this: var loadJson = require('../loadJson'); and used like this: x = loadJson(url); I'd like to spyOn that loadJson function, but it doesn't seem to be possible.…
Steve Bennett
  • 114,604
  • 39
  • 168
  • 219
1
vote
0 answers

how to spyon angular.extend function in jasmine?

My code is as below: angular.extend($scope, { refreshQueries: function() { //code to refresh the tab....... }, queriesTab: { tab: 'queryTab', refreshFunc: $scope.refreshQueries, refreshInterval: 5 } …
Nikesha
  • 47
  • 2
1
vote
1 answer

Testing an Angular directive using Jasmine 2's spyOn

I have an AngularJS directive I'm trying to test with Jasmine 2. Here's a Mock service that I have defined at the beginning my test. var Note = { getNotes: function (type, id) { console.log('I have been called') }, save: function…
Matt Raible
  • 8,187
  • 9
  • 61
  • 120
1
vote
0 answers

using jasmine / spyOn to mock a method only when a particular method is passed

is it possible to mock a method using Jasmine .spyOn(), based only if a certain parameter is a certain value? Basically, imagine I have a GetUser method that I want to mock it such that if it is passed username = 'test', it would send out a test…
Karl Cassar
  • 6,043
  • 10
  • 47
  • 84
1
vote
1 answer

Testing a function inside a function with Jasmine

I have a function that has a function inside it I need to be able to test that the inner function gets called I'v tryed looking for examples of spyOn but not quite found anything I could us the code im trying to test is like function OutterFunc(){ …
TechLiam
  • 137
  • 1
  • 3
  • 10
0
votes
1 answer

jest.spyOn looks like its sharing context across multiple tests (in the same describe)

When I just run my individual test it works. When I run the whole file I get this error. Let's say I have an entity called Group, Group has properties and methods. I'm trying to verify that these methods are called given the conditions scenario. My…
0
votes
1 answer

Mocking side effect function with Vitest

Not sure how I can mock a side-effect function with Vitest in Typescript Node.js project, Vitest 0.33.0. Consider this simplified example: // dummy.ts export function parent(): string { return `foo${child()}`; } export function child(): string { …
Igor
  • 991
  • 3
  • 12
  • 27
0
votes
0 answers

VITEST VUE SCRIPT SETUP: How to test if a method is called inside onMounted

How can you test if a method is called inside the onmount in vue with script setup. The problem is that there is documentation that is done with option api where in the test I can call the component and access its methods, with script setup it is…
0
votes
1 answer

Error with SpyObj how to reassign the value of spy

I'm fairly new to Jasmine so excuse my silly question. I'm trying to override the value of the spy only for one it block and I'm hitting issues. I'm seeing ERROR: : ActionsEnabled has already been spied upon error. How do i fix this? Here is…
TechnoCorner
  • 4,879
  • 10
  • 43
  • 81
0
votes
0 answers

How to correctly spy on setInterval using Jest in unit tests?

I am writing a react application, and also its unit test cases. I am facing a very odd scenario, wherein I am trying to spy on the setInterval ( or setTimeout ) which is placed inside a function, but it is not being called in my test Following is my…
0
votes
1 answer

How can I spy on a function that is returned by a other function with Jest spyOn

I wonder why the last assert (expect(msgSpy).toBeCalled()) in this example fails. What do I need to change to make it pass? it('spyOn test', () => { const newClient = () => { const getMsg = () => { return 'dear spyOn'; }; …
Faber
  • 1,504
  • 2
  • 13
  • 21
0
votes
1 answer

how to use spyon on Matdialog in angular test case

In my test case, I am trying use spyon and call the dialog, but it still says 'Statement not covered' in the coverage report in the line where we are opening the dialog(this._dialog.open(MyDialogComponent) Is there any correct way of doing spyon on…
user1015388
  • 1,283
  • 4
  • 25
  • 45
0
votes
1 answer

how to spyon a service in angular test case in Jasmine

In my angular app, I am writing a test case for a method which call service and returns an object. I am using spyon and callFake and trying to return an Observable. Not sure what is wrong, it is giving an error. Error is : Argument of type '(this:…
user1015388
  • 1,283
  • 4
  • 25
  • 45
0
votes
1 answer

How to mock spyon and return an Observable in Angualr Jasmine Karma Test case

How to spyon an observable and mock data in this scenario. In my angular 14 app, I am writing unit tests using jasmine and karma. Following is the service(UserService) and I want to mock the observable and return mock data. It has a getUserPrefer…
user1015388
  • 1,283
  • 4
  • 25
  • 45