unit-testing-intro | Introduction to Node.js API Unit Testing | Runtime Evironment library
kandi X-RAY | unit-testing-intro Summary
kandi X-RAY | unit-testing-intro Summary
Introduction to Node.js API Unit Testing with Mocha and Chai
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of unit-testing-intro
unit-testing-intro Key Features
unit-testing-intro Examples and Code Snippets
Community Discussions
Trending Discussions on unit-testing-intro
QUESTION
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)
ANSWER
Answered 2018-Aug-09 at 17:03You are just missing break;
statements in the cases of your switch
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install unit-testing-intro
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page