Questions tagged [ts-mockito]

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

32 questions
6
votes
1 answer

How to test void method with Jest

I would like to test if a logger increments correctly (using Jest). Looking at the code below this means I would like check if the increment (1) (meaning the content of the void myMethod) is getting called. // myScript.ts import dd from…
ramo
  • 63
  • 4
6
votes
0 answers

tsmockito - How to mock a function that takes a lambda argument

I have a function that takes a lambda (and the lambda also takes an argument). How can I mock the function? In the example below, I'm trying to mock connection.xmppStanzas: Example class: type Matcher = (t: T) => boolean; const myMatcher:…
Ethan G
  • 1,353
  • 2
  • 15
  • 31
4
votes
1 answer

mock transaction in runTransaction

i want to mock code inside a runTransaction function. example code: await admin.firestore().runTransaction(async transaction => { const hubDocument = admin.firestore().collection("Acme").doc('4'); const hubData = (await…
Andresch Serj
  • 35,217
  • 15
  • 59
  • 101
2
votes
1 answer

How to mock mysql2 `getConnection`

I can't properly mock getConnection method from pool in mysql2 lib. My setup is next: "ts-mockito": "^2.6.1" "typescript": "^4.8.4" "mocha": "^10.1.0", "mysql2": "^2.3.3", Test: import { Pool, PoolConnection } from "mysql2/promise"; import { mock,…
Ivan Pandžić
  • 598
  • 5
  • 20
2
votes
0 answers

IntersectionObserver is not defined

I'm using ts-mockito with jsdom-global to add unit tests to a project which uses IntersectionObserver but unfortunately I'm stumbling on the following error: ReferenceError: IntersectionObserver is not defined Does ts-mockito provide any way…
RAM
  • 2,257
  • 2
  • 19
  • 41
2
votes
1 answer

Ensure spyOnProperty creates configurable properties with Object.defineProperty

In an upgrade to Angular 9 (from 8.1) and Typescript 3.7 (from <3.6), I have encountered an issue with spyOnProperty My service looks like: class Backend { public get baseURL(): string { return 'http://baseurl.com/'; } } My test that worked…
Ian Jamieson
  • 4,376
  • 2
  • 35
  • 55
2
votes
1 answer

How to mock a method using ts-mockito?

I want create a mocked object of a class via ts-mockito@2.5.0 but I am unable to set it up properly. Here's contrived test case: import {expect} from "chai"; import { mock, when, } from "ts-mockito"; class MockMe { public doStuff():…
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
1
vote
1 answer

Verify setter has been called in ts-mockito

Location is defined as follows: interface Location { ... search: string; ... } Let's say I have a service that looks like this: export class MyService { constructor(private readonly location: Location) {} public…
kalsowerus
  • 998
  • 8
  • 23
1
vote
0 answers

How to mock ClientProxy microservice for nestjs in ava test framework

I am trying to give the mock data in ClientProxy but I am keep on receiving null. It could be because of returning Observable. But I cannot figure it out how to properly mock the result. I am using ava framework to write the tests test('get user…
JN_newbie
  • 5,492
  • 14
  • 59
  • 97
1
vote
1 answer

How to test await toPromise() inside async function? (.toPromise() is not a function error)

Based on this question, I wrote this test: it('call service when search product by code', async() => { let code: string = 'CODE'; let product: Product = createProduct(); let properties: ProductProperties = createProductProperties(); …
UrbanoJVR
  • 1,010
  • 1
  • 7
  • 11
1
vote
1 answer

Mocked service does not disable button in angular test?

I am using angular material stepper to navigate in my component have the below button: Below is my stepper.component.html code
avdeveloper
  • 449
  • 6
  • 30
1
vote
1 answer

Mock WebAPI interface using ts-mockito

I'm writing a unit test for a class which uses browser WebAPI interface. I use ts-mockito to mock the interface (a WebGL2RenderingContext in my case). When I run the test, Node throws ReferenceError: WebGL2RenderingContext is not defined which is…
knivex
  • 21
  • 5
1
vote
1 answer

Mocking Express Request with ts-mockito and Typescirpt

Is it possible to mock the class Request from Express using ts-mockito in typescript? I tried the following import { Request, Response } from "express"; const request = mock(Request); const req: Request = instance(request); but get an error on…
bugbear
  • 187
  • 1
  • 11
1
vote
0 answers

Can you mock an interface with a constructor with ts-mockito

First I am not married to ts-mockito it's just what we are using. That being said we have an interface that has a constructor we would like to mock and inject into another class for testing. Is this possible with ts-mockito. No matter what I try I…
austinbv
  • 9,297
  • 6
  • 50
  • 82
1
vote
1 answer

ts-mockito mocked promise never resolves

given this beforeAll(() => { testContainer.register(Beans.CEC_LOCATION, { useFactory: (c) => { const contextMock = mock>(); const entryMock =…
xenoterracide
  • 16,274
  • 24
  • 118
  • 243
1
2 3