NestJS Jest के साथ एकीकृत एक बिल्ट-इन testing utility (@nestjs/testing) प्रदान करता है, और इसका dependency-injection architecture परीक्षण को विशेष रूप से स्वच्छ बनाता है — आप एक testing module बनाते हैं और dependencies के लिए mocks inject करते हैं। Tests unit tests (पृथक) और e2e tests (पूर्ण app) में आते हैं।
एक service का unit testing (mocked dependencies के साथ)
{ } ;
(, {
: ;
mockRepo = { : jest.(), : jest.() };
( () => {
= .({
: [
,
{ : (), : mockRepo },
],
}).();
service = .<>();
});
(, () => {
mockRepo..([{ : , : }]);
result = service.();
(result).();
(mockRepo.).();
});
});
