Skip to content

Commit

Permalink
Fix 4.13 to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
backend-juholee committed Jan 12, 2022
1 parent b5cbc1f commit a793c01
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sections/testingandquality/test-middlewares.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### One Paragraph Explainer

Many avoid Middleware testing because they represent a small portion of the system and require a live Express server. Both reasons are wrong — Middlewares are small but affect all or most of the requests and can be tested easily as pure functions that get `{req,res}` JS objects. To test a middleware function one should just invoke it and spy ([using Sinon for example](https://www.npmjs.com/package/sinon)) on the interaction with the {req,res} objects to ensure the function performed the right action. The library [node-mock-http](https://www.npmjs.com/package/node-mocks-http) takes it even further and factors the {req,res} objects along with spying on their behavior. For example, it can assert whether the http status that was set on the res object matches the expectation (See example below)
미들웨어 테스트는 시스템의 작은 부분을 차지하며 라이브 Express 서버가 필요하기 때문에 대부분 미들웨어 테스트를 회피합니다. 두 가지 이유 모두 틀렸습니다. 미들웨어는 작지만 요청의 전부 또는 대부분에 영향을 미치며 '{req,res}' JS 개체를 가져오는 순수 함수로 쉽게 테스트할 수 있습니다. 미들웨어 함수를 테스트하려면 해당 함수를 호출하고 {req,res}개 개체와의 상호 작용에 대해 [예를 들어 Sinon 사용](https://www.npmjs.com/package/sinon)))을 스파이하여 함수가 올바른 동작을 수행했는지 확인해야 합니다. 라이브러리 [node-controls-products](https://www.npmjs.com/package/node-mocks-http)는 더 나아가서 {req,res}개의 객체의 동작에 대한 스파이 활동과 함께 인자를 분석합니다. 예를 들어 res 개체에 설정된 http 상태가 예상과 일치하는지 여부를 주장할 수 있습니다(아래 예 참조).

<br/><br/>

Expand All @@ -20,8 +20,8 @@ test("A request without authentication header, should return http status 403", (
method: "GET",
url: "/user/42",
headers: {
authentication: ""
}
authentication: "",
},
});
const response = httpMocks.createResponse();
unitUnderTest(request, response);
Expand Down

0 comments on commit a793c01

Please sign in to comment.