Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [unit-testing]

Unit testing is a method by which individual units of source code are tested to determine if they are fit for use.

0 votes
0 answers
5 views

Error with pg in Jest-ts testing : Jest has detected the following 1 open handle potentially keeping Jest from exiting: ● TCPWRAP

I have been facing the problem where my Jest test is not ending gracefully. (I prefer not to use --force-exit). this is my jest code. FYI the tests passes. This is an integration testing. import ...
IamDealer's user avatar
0 votes
1 answer
19 views

How to test that a function returned without doing anything

I'm writing a suite of Jest tests, and the following question came up. How can I test that a function simply returns if it receives an invalid argument? For example, I would like to test that the ...
Eric's user avatar
  • 1,461
0 votes
1 answer
10 views

How to mock React.UseContext with Jest

I am trying to write a unit test for a component that contains the usage of values that come from a context file. import { globalContext } from "../../globalContext"; const { rowId, num, ...
wrj's user avatar
  • 19
0 votes
0 answers
12 views

How to test a service layer in spring with mockito?

I mocked repository and service. I used when().thenReturn() method with verify but it seems that repository and service are null. For both mocked service and repository the value returned by calling ...
Hekima's user avatar
  • 1
0 votes
1 answer
13 views

What are the possible ways we can handle the case when the setup code of a test fixture requires to be tested itself without violating best practices? [closed]

What are the possible ways we can handle the case when the setup code of a test fixture requires to be tested itself without violating best practices? Consider the following code in C# 12.0/.NET 8.0 ...
Hashkoon's user avatar
-1 votes
0 answers
9 views

WebClient static mock is not working the second time is called in a test

I have the next static mock: try (MockedStatic<WebClient> webClientStatic = Mockito.mockStatic(WebClient.class)) { webClientStatic.when(WebClient::builder).thenReturn(...
rasilvap's user avatar
  • 1,989
0 votes
1 answer
19 views

How to write a test against randomly selected values from a collection?

I have a function which selects a random value from an array to be returned: export function selectMovieUnderDuration(options: IStreamRequest, movies: Movie[], prevMovies: Movie[], duration: number): ...
JSArrakis's user avatar
  • 789
0 votes
0 answers
7 views

Is there a way to make a variable available globally from the `beforeAll` function in Vitest?

For example, I want to make this something variable from inside the beforeAll block grabbable from my unit test suites. import { beforeAll } from 'vitest' beforeAll(async () => { let something = ...
jiamijiang's user avatar
0 votes
2 answers
31 views

Is there a generic way to use SetReturnsDefault in Moq

I have a data access interface looking roughly like this: public interface IDataRepository { DatabaseResult<Customer> GetAllCustomers(); DatabaseResult<Report> GetAllReports(); ...
user1151923's user avatar
  • 1,862
2 votes
1 answer
16 views

Angular: how to fix Error: NG03600: Angular detected that the `AnimationBuilder` was injected, but animation support was not enabled

When I ran Angular unit test I got the following error many times: Error: NG03600: Angular detected that the AnimationBuilder was injected, but animation support was not enabled. Please make sure that ...
L. Kvri's user avatar
  • 1,612
0 votes
0 answers
38 views

Is MockObject necessary - GTest segmentation fault

Google test with fixture's got segmentation fault Inextricably I find segmentation fault every time compiling Google unit test. In explanation I compile Google test without problem for test without ...
gzifl-67's user avatar
0 votes
0 answers
21 views

how to mock a third party library and assert its functions were called (or spyon) with jest?

I am working with ngrx and signalr, and writing a unit test for my ngrx effect responsible for building, starting and stopping the signalR hub. this is my effect: import {HubConnection, ...
Natalia Cáceres's user avatar
1 vote
1 answer
16 views

Picocli unit test failed for registering subcommands programmatically

In picocli we can register subcommands declaratively and programmatically. It works both way, but the unit test according the docs failed for the programmatically version. This is the unit test: @Test ...
Dominik's user avatar
  • 1,412
0 votes
0 answers
24 views

create migrations in an unit test project

I have an ASP.NET Core Web API project with EF Core and a SQL Server database using the repository pattern. All works fine. I added to the solution an xUnit test project and referenced the Web API ...
derstauner's user avatar
  • 1,716
0 votes
0 answers
12 views

TypeScript JSX Syntax Error in Jest Mock for react-native-modal: Operator ‘>’ cannot be applied to types ‘View’ and ‘{ children: React.ReactNode; }’

I’m trying to create a Jest mock for react-native-modal in a React Native project using TypeScript. However, TypeScript doesn’t recognize the return statement as valid JSX. It throws the following ...
Mike S.'s user avatar
  • 2,706

15 30 50 per page