# fastify-knexjs-mock

> Fastify KnexJS Mock Plugin

Latest version **1.1.1** (published 2021-02-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install fastify-knexjs-mock
pnpm add fastify-knexjs-mock
yarn add fastify-knexjs-mock
bun add fastify-knexjs-mock
```

## 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.1.1 |
| Published | 2021-02-10 |
| First published | 2017-12-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 10.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Nicolas Balduzzi |
| Maintainers | nbalduzzi |
| Keywords | Fastify, KnexJS, Mock, Test |

## Links

- npm: https://www.npmjs.com/package/fastify-knexjs-mock
- Repository: https://github.com/nbalduzzi/fastify-knexjs-mock
- Homepage: https://github.com/nbalduzzi/fastify-knexjs-mock#readme
- Issues: https://github.com/nbalduzzi/fastify-knexjs-mock/issues
- npm.io page: https://npm.io/package/fastify-knexjs-mock

## Dependencies (3)

- [knex](https://npm.io/package/knex.md) ^0.21.17
- [mock-knex](https://npm.io/package/mock-knex.md) ^0.4.9
- [fastify-plugin](https://npm.io/package/fastify-plugin.md) ^3.0.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2021-02-10
- 1.1.0 — 2021-02-09
- 1.0.0 — 2021-02-09
- 1.0.21 — 2019-04-18
- 1.0.20 — 2019-04-18
- 1.0.19 — 2018-09-27
- 1.0.18 — 2018-09-27
- 1.0.16 — 2018-09-18
- 1.0.15 — 2018-05-17
- 1.0.14 — 2018-05-14
- 1.0.13 — 2018-05-01
- 1.0.12 — 2018-02-20
- 1.0.11 — 2018-02-20
- 1.0.10 — 2017-12-11
- 1.0.9 — 2017-12-05
- … 8 more at https://npm.io/package/fastify-knexjs-mock/versions

## README

# Fastify KnexJS Mock Plugin

![Test](https://github.com/nbalduzzi/fastify-knexjs-mock/workflows/Test/badge.svg)
![Semantic Release](https://github.com/nbalduzzi/fastify-knexjs-mock/workflows/Semantic%20Release/badge.svg)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

[![NPM](https://nodei.co/npm/fastify-knexjs-mock.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/fastify-knexjs-mock/)

## Installation

```bash
npm install fastify-knexjs-mock --save
```

## Usage

```bash
fastify.register(require('fastify-knexjs-mock'), options, err => console.error(err))

fastify.get('/', (request, reply) => {
  console.log(fastify.knex) // Knex DB instance
  console.log(fastify.tracker) // Knex DB Mocked tracker
})
```

## Options

KnexJS Mock DB configuration JSON object.

<https://github.com/colonyamerican/mock-knex>

## Test example

```javascript
const { test } = require('tap')
const { fastify } = require('./app')

fastify.ready(() => {
  fastify.tracker.install()

  test('GET 200 `/users` route', async t => {
    t.plan(2)

    fastify.tracker.on('query', (query) => query.response([{
      id: 1,
      name: 'Test',
      lastname: 'Test',
      email: 'test@example.com'
    }]))

    try {
      const { statusCode, payload } = await fastify.inject({
        method: 'GET',
        url: '/users'
      })

      t.equal(statusCode, 200)
      t.same(JSON.parse(payload)[0].email, 'test@example.com')
    } catch (err) {
      t.error(err)
    } finally {
      fastify.close(() => t.end())
    }
  })
})
```

## Author

[Nicolás Balduzzi](nico.balduzzi@gmail.com)

## License

Licensed under [MIT](./LICENSE).

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