@pubcore/knex-create-test-db

1.1.13 • Public • Published

Helper to create on-the-fly sql database tables to test knex with mocha

Prerequisite

  • mocha used for tests
  • knex used for database (RDMS) persitence functions to test

Example

import {expect} from 'chai'
import createKnex from '@pubcore/knex-create-test-db'

var rows = [
    {author:'king', published:new Date(), sold:42}
  ],
  table = 'books',
  dbTypes = {author:'string', published:'dateTime', sold:'integer'}

describe('create test db', () => {
  //The test table will be created and droped for each "it" ("beforeEach" callback)
  //Knex will be destroyed after "describe" block finished ("after" callback)

  var knex = createKnex({table, rows, beforeEach, after, dbTypes})

  it('can be used to test some functionality dealing with a knex api', () => {
    expect( bookAvailable({author:'king'}, {db:{knex}}) ).to.be.true
  })
})

Readme

Keywords

Package Sidebar

Install

npm i @pubcore/knex-create-test-db

Weekly Downloads

4

Version

1.1.13

License

MIT

Unpacked Size

12.7 kB

Total Files

8

Last publish

Collaborators

  • dominix
  • jacklrs
  • fidorw