# nodeunit-httpclient

> HTTP response testing for NodeUnit

Latest version **0.2.1** (published 2012-05-02) · 0 weekly downloads

## Install

```sh
npm install nodeunit-httpclient
pnpm add nodeunit-httpclient
yarn add nodeunit-httpclient
bun add nodeunit-httpclient
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2012-05-02 |
| First published | 2011-11-17 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.4.1 |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Charles Davison |
| Maintainers | powmedia |

## Links

- npm: https://www.npmjs.com/package/nodeunit-httpclient
- npm.io page: https://npm.io/package/nodeunit-httpclient

## Dependencies (1)

- [underscore](https://npm.io/package/underscore.md) 1.1.7

## Recent versions

- 0.2.1 (latest) — 2012-05-02
- 0.2.0 — 2012-05-02
- 0.1.1 — 2011-12-19
- 0.1.0 — 2011-11-17

## README

nodeunit-httpclient
===================

HTTP response testing for NodeUnit

Usage
-----

    //Setup client with automatic tests on each response
    var api = require('nodeunit-httpclient').create({
        port: 3000,
        path: '/api',   //Base URL for requests
        status: 200,    //Test each response is OK (can override later)
        headers: {      //Test that each response must have these headers (can override later)
            'content-type': 'application/json'  )
        }
    });
    
    //Automatic tests on response object
    exports.test1 = function(test) {
        api.get(test, '/user/nonexistent', {
            status: 404,
            headers: { 'content-type': 'text/plain' },
            body: 'Not found'
        })
    };

    //Test a response
    exports.test2 = function(test) {
        api.get(test, '/user', function(res) {
            //JSON responses are automatically parsed:
            test.equal(res.json, [{ name: 'Eric' }, { 'name': 'Kyle' }]);

            test.done();
        });
    };
    
    //POST with data and custom header
    exports.test3 = function(test) {
        api.post(test, '/user', {
            headers: { foo: 'bar' },
            data: { name: 'Charlie' } //Objects are serialised as JSON automatically
        }, {
            status: 200
        }, function(res) {
            test.equal(1, 1);
            
            test.done();
        });
    };
    

Changelog
---------

0.2.0
- Handle 204 No Content responses

---
_Source: https://npm.io/package/nodeunit-httpclient · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
