1.1.1 • Published 3 years ago

fastify-knexjs-mock v1.1.1

Weekly downloads
33
License
MIT
Repository
github
Last release
3 years ago

Fastify KnexJS Mock Plugin

Test Semantic Release JavaScript Style Guide semantic-release

NPM

Installation

npm install fastify-knexjs-mock --save

Usage

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

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

License

Licensed under MIT.

1.1.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago