7

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?

1 Answer 1

1

It's because global.app.models.User is your model's definition and not the waterline model. This one is under global.app.orm.User, after that you can use User.create without any problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.