Category "unit-testing"

HTTP POST request test is not getting passed

I wrote some nodejs codes to be evaluated by a particular test file, candidate.test.js but surprisingly the test keeps failing. Below is the error I am getting:

ReferenceError: window is not defined, consider using the "jsdom" test environment (jest V28)

I would like some assistance in resolving this error. Am using Jest V28.0.0. Here's how my package.json's test script & devDependencies look like "scri

Nextjs Api unit test - difficult to mock prisma client

I am stuck since long as it is kind of difficult to mock DB calls in unit testing in Nextjs. I have used @prisma/client for database communication. I have studi

Angular unit test calling readonly BehaviorSubject

I have a angular class implemented ControlValueAccessor interface too. I need to have 100% coverage. Please help me to cover the remain. Line 20, 35, 36 need to

Nestjs unit test: TypeError: this.userModel.findById(...).exec is not a function

using nestjs framework and with a repository class that uses mongoose to do the CRUD operations we have a simple users.repository.ts file like this: @Injectable

pytest (or unittest) not working when a source file has a dependency

I'm not sure why this is so difficult to get going, but I'm new to Python and I'm trying to get any unit test framework to run tests, but if I test a file that

How to do Unit Testing with gorm

I'm new in Go and unit test. In my project am using Go with gorm and connecting mysql database. my queries is how to unit test my code: My code is below(main.go

CRA - window object is undefined - jest/react

I have an issue in my tests that flag up a window variable as undefined. But I don't know where in the setupTests.tsx, I would need to define it. So far the var

React Testing Library gives console error for ReactDOM.render in React 18

After updating to React 18 or creating a new React 18 app from create-react-app, when I run the yarn test command, it gives a console.error as a Warning for eac

Flutter: How can I unit test a Timer used by a Bloc using blocTest?

How can I test a Timer inside a Bloc, using blocTest? I’m using the bloc library, with freezed to build the state and event objects (might not matter here

How to apply test-driven development for storing data on db?

Let us assume that the next feature that I have to develop is to store some data on a database. Following the TDD paradigm, I have to first write a failing test

NullPointerException when MockMvc performed in unit test

I'm trying to write a Java unit test but not sure where I'm going wrong. Likely a lack of understanding. This is my test so far: @Test public void getURL() thro

Simplifying AWS SDK GO v2 testing/mocking

Amazon has a super useful article describing how to unit test AWS SDK Go v2. I understand their motivation to depart from the "old" way of unit testing the v1

How to make MSTest grab all console output from unit test? Output behind WebHost.CreateDefaultBuilder() goes missing (VS2022, .NET 6, MSTest 2.2.10)

I'm creating an integration test for a Web API, so I'm starting an entire application in a unit test using WebHost.CreateDefaultBuilder() and the usual setup bi

How to distinguish between two calls of the same method based on the argumetns?

I'm using sinon to stub functions of the Google Drive in my NodeJS application. I do two different calls of the create method under the same test (I can't do re

Xunit in asp.net core

I'm new at asp.net and moq and xunit test, I want to create a test case for my asp.net project. I have the service file that is CRUD action, I have been written

Is there a way of formatting failed output from Laravel's assertSee() test?

Laravel has several built-in assertions that allow you to query the Response from a Request. public function testWebpage() { $response = $this-&

How can I represent map[string][]byte? [closed]

I would like to create a map, but I am unsure of the syntax. The map[string][]byte data type is giving me trouble, because I think that the e

How to mock only one typescript class from a module, but leave other classes/functions as is, using the jest framework

I have a typescript module with a function that I'm trying to test with jest. The function I'm trying to test uses a typescript class that's defined in the same

I am trying to set a cookie in supertest but it does not work

I am trying to set a cookie session to a post request in supertest but I cannot. This is my test code: const app = express(); app.set("trust proxy", true); app