0

am learning sinon and nodeUnit for nodejs. wrote simple module that handles GET, POST, PUT and DELETE methods.

then started writing unit test. Now there are two sides for my problem:

One being: in GET test when i specify requestMock.method = 'GET'; then run nodeunit test-http-module.js test fails, when reviewing call stack it says POST request failed (handlePostRequest as highlighted in call stack below).

Two being: when changing requestMock.method = 'GET'; to 'POST', 'PUT' or 'DELETE' test still fails no matter what i change! but in latter cases the call stack shows the correct method being directed to.

I think there is a single problem causing the continuous failures and that GET being directed to POST.

please explain what is wrong.

ExpectationError: Unexpected call: writeHead(200, { Content-Type: "text/plain" })

Expectation met: writeHead(200, { Content-Type: "text/plain" }[, ...]) once

at Object.fail (D:\Projects\node-book\node_modules\sinon\lib\sinon\mock-expectation.js:281:25)

at Object.invokeMethod (D:\Projects\node-book\node_modules\sinon\lib\sinon\mock.js:174:25)

at Object.writeHead (D:\Projects\node-book\node_modules\sinon\lib\sinon\mock.js:67:35)

at handlePostRequest (D:\Projects\node-book\modules\http-module.js:8:14)

at Object.handleRequest (D:\Projects\node-book\modules\http-module.js:34:26)

at Object.exports.handleGetRequestTest (D:\Projects\node-book\unit-testing-intro\test-http-module.js:22:21)

4

1 回答 1

0

You are just missing break; statements in the cases of your switch.

于 2018-08-09T17:03:11.053 回答