NestJS ਇੱਕ built-in testing utility (@nestjs/testing) ਫਰਾਹਮ ਕਰਦਾ ਹੈ ਜੋ Jest ਨਾਲ ਏਕਿਤ ਹੈ، ਅਤੇ ਇਸਦੀ dependency-injection ਆਰਕੀਟੈਕਚਰ ਪਰੀਖਿਆ ਨੂੰ ਖਾਸ ਤੌਰ 'ਤੇ ਸਾਫ ਬਣਾਉਂਦੀ ਹੈ — ਤੁਸੀਂ ਇੱਕ testing module ਬਣਾਉਂਦੇ ਹੋ ਅਤੇ dependencies ਲਈ mocks ਨੂੰ inject ਕਰਦੇ ਹੋ। ਪਰੀਖਿਆਵਾਂ unit tests (ਵੱਖ ਕੀਤੀਆਂ) ਅਤੇ e2e tests (ਪੂਰੀ ਐਪ) ਵਿੱਚ ਆਉਂਦੀਆਂ ਹਨ।
ਇੱਕ service ਦੀ unit testing (mocked dependencies ਦੇ ਨਾਲ)
{ } ;
(, {
: ;
mockRepo = { : jest.(), : jest.() };
( () => {
= .({
: [
,
{ : (), : mockRepo },
],
}).();
service = .<>();
});
(, () => {
mockRepo..([{ : , : }]);
result = service.();
(result).();
(mockRepo.).();
});
});
