Skip to content

Commit

Permalink
feat: update readme description
Browse files Browse the repository at this point in the history
  • Loading branch information
KHYehor committed Oct 13, 2024
1 parent bfa8eef commit 5cee350
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
- [License](#license)

## Description

This repository demonstrates how to effectively set up and execute integration tests for a Node.js application without using mocks inside **node.app:**

Typically, when it comes to setting up integration tests and working with external dependencies, an approach is used where components are simulated through mocks. This means that database responses or requests via `axios` are artificially replaced with pre-defined results directly in the code. However, this repository demonstrates an alternative approach, where the tests interact with real external services, allowing for more accurate and comprehensive end-to-end validation of the application's functionality.
```typescript
const moduleRef: TestingModule = await Test.createTestingModule({
controllers: [UserController],
Expand All @@ -27,8 +25,7 @@ const moduleRef: TestingModule = await Test.createTestingModule({

userController = moduleRef.get<UserController>(UserController);
```

Instead of simulating components in code like mocking what database or axios returns, the approach focuses on testing real interactions between outside services, ensuring more accurate, end-to-end validation of your application’s behavior. If you think about how your app should interact with external client or provider api without mocks of axios **(example below)**:
Rather than simulating components in code by mocking responses from the database or axios, this approach focuses on testing real interactions with external services. This ensures more accurate, end-to-end validation of your application's behavior. If you want to test how your app interacts with external client or provider APIs without mocking tools like axios, consider the following example:
```typescript
import axios from 'axios';
// Set up an interceptor to mock requests
Expand All @@ -45,7 +42,7 @@ axios.get('https://api.example.com')
.then(response => console.log(response.data)) // Logs 'mocked success'
.catch(error => console.error(error));
```
The answer is [mockserver](https://www.mock-server.com). I hope you know all possible scenarios and responses the provider api can return. You define a schema with info of expected request and response for it, like return this response if you catch this request:
The solution for more realistic testing is using [mockserver](https://www.mock-server.com). This approach allows you to define expected request-response schemas, ensuring that your app reacts correctly to all possible scenarios from the provider API. For example, you can specify:
```json
{
"httpRequest": {
Expand All @@ -57,7 +54,7 @@ The answer is [mockserver](https://www.mock-server.com). I hope you know all pos
}
}
```
The schema can be more detailed, it depends on your needs. Mocking DB or publishing events to message brokers is easier and cause no problems. In general node.js code wasn't modified or changed (except environmental variables for api calls). Now your scenarios are tested and you can be confident about identical behavior on production.
The schema can be more detailed based on your needs. Mocking the database or handling events in message brokers is simpler and typically hassle-free. The core Node.js code remains unchanged (apart from adjusting environment variables for API calls). Now your scenarios are thoroughly tested, giving you confidence that the behavior will be consistent in production.
## Key Features
- **No Code Mocking: Focuses on testing real integrations, without relying on mocks or stubs in node.js.**
- **Production-like Testing: Verifies how the app interacts with external services in a more realistic, production-like environment.**
Expand Down

0 comments on commit 5cee350

Please sign in to comment.