Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nbalduzzi/fastify-knexjs-mock
Fastify KnexJS Mock
https://github.com/nbalduzzi/fastify-knexjs-mock
Last synced: 2 months ago
JSON representation
Fastify KnexJS Mock
- Host: GitHub
- URL: https://github.com/nbalduzzi/fastify-knexjs-mock
- Owner: nbalduzzi
- License: mit
- Created: 2017-12-02T11:59:26.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-23T07:01:52.000Z (almost 2 years ago)
- Last Synced: 2024-08-20T06:01:04.158Z (5 months ago)
- Language: JavaScript
- Size: 456 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fastify - `fastify-knexjs-mock`
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.
## 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: '[email protected]'
}]))try {
const { statusCode, payload } = await fastify.inject({
method: 'GET',
url: '/users'
})t.equal(statusCode, 200)
t.same(JSON.parse(payload)[0].email, '[email protected]')
} catch (err) {
t.error(err)
} finally {
fastify.close(() => t.end())
}
})
})
```## Author
[Nicolás Balduzzi]([email protected])
## License
Licensed under [MIT](./LICENSE).