[Pkg-javascript-commits] [node-mocks-http] 51/296: Updates the example to match the README.md and updates the README.md by organizing some sections.
Thorsten Alteholz
alteholz at moszumanska.debian.org
Mon Feb 8 18:13:20 UTC 2016
This is an automated email from the git hooks/post-receive script.
alteholz pushed a commit to branch master
in repository node-mocks-http.
commit a779fe357e4cacf9d8b86dcd8411feed22b38b77
Author: Alan James <alanjames1987 at gmail.com>
Date: Thu Sep 25 18:01:03 2014 -0400
Updates the example to match the README.md and updates the README.md by organizing some sections.
---
README.md | 26 +++++++++++--
examples/express-route.js | 98 +++++++++++++++++++++++++----------------------
2 files changed, 75 insertions(+), 49 deletions(-)
diff --git a/README.md b/README.md
index 7d964d9..9c2da8b 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
node-mocks-http
---
-Mock 'http' objects for testing Express routing functions, but could be used
+Mock 'http' objects for testing [Express](http://expressjs.com/) routing functions, but could be used
for testing any [Node.js](http://www.nodejs.org) web server applications that
have code that requires mockups of the `request` and `response` objects.
@@ -61,6 +61,7 @@ exports['routeHandler - Simple testing'] = function(test) {
test.ok( response._isEndCalled());
test.ok( response._isJSON());
test.ok( response._isUTF8());
+
test.done();
};
@@ -84,11 +85,22 @@ This project doesn't address all features that must be
mocked, but it is a good start. Feel free to send pull requests,
and a member of the team will be timely in merging them.
-After making any changes, please verify your work:
+After making any changes, please verify your works.
+
+Running Tests
+---
+
+Install `jshint` globally.
```bash
npm install -g jshint
-npm install
+```
+
+Navigate to the project folder and run `npm install` to install the project's dependencies.
+
+Then simply run the tests.
+
+```bash
./run-tests
```
@@ -97,4 +109,10 @@ Release Notes
Most releases fix bugs with our mocks or add features similar to the
actual `Request` and `Response` objects offered by Node.js and extended
-by Express.
\ No newline at end of file
+by Express.
+
+
+License
+---
+
+Licensed under [MIT](https://github.com/howardabrams/node-mocks-http/blob/master/LICENSE).
\ No newline at end of file
diff --git a/examples/express-route.js b/examples/express-route.js
index c9f9f08..94a5c9e 100644
--- a/examples/express-route.js
+++ b/examples/express-route.js
@@ -2,52 +2,60 @@
var httpMocks = require('../lib/http-mock');
-// Suppose we have the following magical Express incantation:
-//
-// app.get('/user/:id', mod.aroute);
-//
-// And we have ourselves a function to answer that call:
-
-var aroute = function (request, response) {
-
- var id = request.params.id;
- console.log('We have a \'%s\' request for %s (ID: %d)',
- request.method, request.url, id);
-
- var body = {
- name: 'Bob Dog',
- age: 42,
- email: 'bob at dog.com'
- };
- response.setHeader('Content-Type', 'application/json');
- response.statusCode = 200;
- response.send(JSON.stringify(body), 'utf8');
- response.end();
+// Suppose you have the following Express route:
+
+// app.get('/user/:id', routeHandler);
+
+// And you have created a function to handle that route's call:
+
+var routeHandler = function(request, response) {
+
+ var id = request.params.id;
+
+ console.log('We have a \'%s\' request for %s (ID: %d)', request.method, request.url, id);
+
+ var body = {
+ name: 'Bob Dog',
+ age: 42,
+ email: 'bob at dog.com'
+ };
+
+ response.setHeader('Content-Type', 'application/json');
+ response.statusCode = 200;
+ response.send(JSON.stringify(body), 'utf8');
+ response.end();
+
};
// -----------------------------------------------------------------
-// In another file, we can now test that function, like so:
-
-exports['aroute - Simple testing'] = function (test) {
- var request = httpMocks.createRequest({
- method: 'GET',
- url: '/user/42',
- params: {
- id: 42
- }
- });
- var response = httpMocks.createResponse();
-
- aroute(request, response);
-
- var data = JSON.parse(response._getData());
- test.equal('Bob Dog', data.name);
- test.equal(42, data.age);
- test.equal('bob at dog.com', data.email);
-
- test.equal(200, response.statusCode);
- test.ok(response._isEndCalled());
- test.ok(response._isJSON());
- test.ok(response._isUTF8());
- test.done();
+// In another file, you can easily test the routeHandler function
+// with some code like this using the testing framework of your choice:
+
+exports['routeHandler - Simple testing'] = function(test) {
+
+ var request = httpMocks.createRequest({
+ method: 'GET',
+ url: '/user/42',
+ params: {
+ id: 42
+ }
+ });
+
+ var response = httpMocks.createResponse();
+
+ routeHandler(request, response);
+
+ var data = JSON.parse(response._getData());
+
+ test.equal('Bob Dog', data.name);
+ test.equal(42, data.age);
+ test.equal('bob at dog.com', data.email);
+
+ test.equal(200, response.statusCode);
+ test.ok(response._isEndCalled());
+ test.ok(response._isJSON());
+ test.ok(response._isUTF8());
+
+ test.done();
+
};
\ No newline at end of file
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-mocks-http.git
More information about the Pkg-javascript-commits
mailing list