Questions tagged [ts-mockito]

Mocking library for TypeScript inspired by http://mockito.org/

32 questions
1
vote
0 answers

How to mock component instance event

I want to test an event (dialogEvent) which is being triggered from a material dialog instance with ts-mockito: myFunc() { this.matDialogRef = this.matDialog.open(DialogComponent); …
DonJuwe
  • 4,477
  • 3
  • 34
  • 59
1
vote
1 answer

How to verify store function call?

Start practices unit testing. And faced with such problem: I am trying to test store method call. When I run this test: import * as React from 'react'; import {observer} from 'mobx-react'; import {mount} from 'enzyme'; import {instance, mock,…
0
votes
0 answers

ts-mockito mock object fails

I'm trying to use the ts-mockito library to mock the Open Telemetry object NodeTracerProvider, imported from @opentelementry/sdk-trace-node. However, it looks like the real object is being called rather than the mock object, as the log records…
0
votes
1 answer

ts-mockito: When mocking a function named `execute`, I get "execute is not a function"

I am testing a typescript project with ts-mockito and jest. Getting errors like this on a function called execute: Error: 'MyAbstractClass.execute' is not a function // main.ts abstract class MyAbstractClass { abstract execute(arg):…
n8m8
  • 41
  • 6
0
votes
1 answer

Issues mocking objects in Typescript with ts-mockito

When I try to use mockito-ts to mock the return value of member functions on instances of mocked objects, I get that the member function is not a function. TypeError: Cannot read properties of null (reading 'methodStubCollection') When I ran this in…
0
votes
0 answers

mockModuleRef.get is not a function

I am using moduleRef in NestJS like this: this.moduleRef.get(X) In unit tests which is implemented with ts-mockito I try to mock like this: describe(() => { const mockModuleRef = mock(ModuleRef); const mockX = mock(X); beforeEach(()…
Oğuzcan Budumlu
  • 511
  • 1
  • 4
  • 11
0
votes
0 answers

ts-mockito verify the params a function is called with

I am trying to test the testingThisFunction of the sampleClass class that looks like this. class sampleClass { public async testingThisFunction(options:any): Promise { const result =…
Rachit Anand
  • 616
  • 5
  • 16
0
votes
1 answer

Why do I get an AssertionError: expected MethodToStub on mocking a method returning a promise

On entering a world of MEAN, I am also entering a world of promises. Now I got this problem: const promise = new Promise(() => {}); const testObject = mock(DB_DAO_object); when…
0
votes
2 answers

How to mock a named nestjs Logger with ts-mockito

Our project uses nestjs with mocha, chai and ts-mockito for testing and I can't figure out how to test a named nestjs Logger. new Logger() can be tested as expected: describe('basic test', () => { it('works', async () => { const…
qujck
  • 14,388
  • 4
  • 45
  • 74
0
votes
1 answer

How to mock imported function in ts-mock

I'm new to typescript and playing around with aws-lambda. I'm trying to unit test my handler so I need to mock the service class so it will return some mocked data Below I have a simple function that gets the data from the domain…
Ruelos Joel
  • 2,209
  • 3
  • 19
  • 33
0
votes
1 answer

ts-mockito verifying not correctly

Hi I am stuck on the tests for longer than i would like to admit. But I need help on my test. I console logged the class I want to test and the code flow I need to be tested. But when i call veryfy on my function that is called, ts-mockito returns…
0
votes
0 answers

Test HttpErrorResponse from ts-mockito mocked service

I'm having trouble in my component spec testing error scenarios from my service class. The service class is mocked using ts-mockito. Service class: export class MyService { getData(): Observable { /* return httpClient.get(...) */ …
0
votes
1 answer

Angular manipulate service value inside test

I'm trying to manipulate the service return value in my test and attach that value to components field. So I mock myService inside the Test1 and manipulate its value as true so that it always returns true. With the call fixture.detectChanges(); I…
Korki Korkig
  • 2,736
  • 9
  • 34
  • 51
0
votes
1 answer

throw an error using ts-mockito in async function

I am trying to test an API endpoint using ts-mockito. Things went well until I started going async... my test: it('should throw an error if the address is not valid',()=>{ const mockedGeolocationService: GoogleGeolocationService =…
JMir
  • 137
  • 1
  • 10
0
votes
0 answers

How to inject a ts-mockito mock object in the controller

My background is PHP (Laravel base) So forgive me if I'm not 100% how Typescript/Nodejs suppose to work off the bat. I am trying to test a controller with supertest and my project is made using restify and inversify for DI. Using Mocha/Chai and…
azngunit81
  • 1,574
  • 2
  • 20
  • 38