@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
  })
})

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.13
    0
    • latest

Version History

Package Sidebar

Install

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

Weekly Downloads

0

Version

1.1.13

License

MIT

Unpacked Size

12.7 kB

Total Files

8

Last publish

Collaborators

  • dominix
  • jacklrs
  • fidorw