NestJS provides a built-in testing utility (@nestjs/testing) integrated with Jest, and its dependency-injection architecture makes testing especially clean — you create a testing module and inject mocks for dependencies. Tests fall into unit tests (isolated) and e2e tests (full app).
Unit testing a service (with mocked dependencies)
{ } ;
(, {
: ;
mockRepo = { : jest.(), : jest.() };
( () => {
= .({
: [
,
{ : (), : mockRepo },
],
}).();
service = .<>();
});
(, () => {
mockRepo..([{ : , : }]);
result = service.();
(result).();
(mockRepo.).();
});
});
