# fake-express

> Mock express js objects with any test framework such as Jest or Sinon, chai and mocha

Latest version **1.0.1** (published 2018-12-21) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install fake-express
pnpm add fake-express
yarn add fake-express
bun add fake-express
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2018-12-21 |
| First published | 2018-12-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mark Jefferson Arthur |
| Maintainers | mrkjffrsn |
| Keywords | mock, expressjs, express-request, express-response |

## Links

- npm: https://www.npmjs.com/package/fake-express
- Repository: https://github.com/mrkjffrsn/FakeExpress
- Homepage: https://github.com/mrkjffrsn/FakeExpress#readme
- Issues: https://github.com/mrkjffrsn/FakeExpress/issues
- npm.io page: https://npm.io/package/fake-express

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [@noahbleau/winfio](https://npm.io/package/@noahbleau/winfio.md) — 0 weekly downloads
- [@nocville/node](https://npm.io/package/@nocville/node.md) — 0 weekly downloads
- [@webda/mock](https://npm.io/package/@webda/mock.md) — 0 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2018-12-21
- 1.0.0 — 2018-12-21

## README

# FakeExpress

A fake express.js module that could be useful when mocking express objects within any test framework.
The module returns an object that resembles an `express` object.

### How to Use

The below example illustrates how the express double could be used for mocking within the jest framework

Test Code on a file called `snacksController`

```
const snackService = require('../../services/snacks');

const getSnacks = (req, res, next) => {

  return snackService.getSnacks().then((data) => {
      console.log( "On Success --- " )
      if (data != null)
      {
        res.status(200).json(data);
      }
      }, (error) => {
          res.status(400).json(error);
          console.log( "Service Promise error ", error );
        }
      );
  }

module.exports = { getSnacks };
```

A test suite for the above snacks controller

```

// { Request: {}, Response: {}, Router: {}, next: () => {} }
const express = require('fake-express`)

// Mock the response object
const response = jest.genMockFromModule('../../fakes/fakeExpress').Response;


test('get snacks positive test', async () => {
  // Set up
  let snacksData = { name: 'testName', id: 1 };

  snackService.getSnacks.mockResolvedValue(snacksData);
  response.status.mockReturnThis();
  response.json.mockReturnValue(snacksData);

  // Exercise
  await snacksController.getSnacks(null, response, null);

  // Verify
  expect(snackService.getSnacks.mock.calls.length).toBe(1);
  expect(response.status.mock.calls.length).toBe(1);
  expect(response.status.mock.calls[0][0]).toBe(200);
  expect(response.json.mock.calls.length).toBe(1);
  expect(response.json.mock.calls).toEqual([[snacksData]]);
});
```

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