I wanted to test the models of my Trails.js project with mocha. I use the trailpack-waterline to load my models into the Waterline ORM.
Following the Trails Docs I created a User.test.js
:
'use strict'
const assert = require('assert')
describe('User Model', () => {
let User
before(() => {
assert(global.app.models.User)
User = global.app.models.User
})
it('should exist', () => {
assert(User)
})
})
This runs without any error.
But I cannot instantiate the model in any way. Following the example of the Docs new User({...})
should create a new user object, but this code throws an error saying User is not a constructor
. And neither the example of the Waterline Docs using User.create({...})
seems to work.
Printing out the User model shows it consists of only two methods: [ 'getModelName', 'getTableName' ]
.
How do I instantiate a waterline Model for unit testing?