How to check waterline models in Trails.js

I wanted to test the models of my Trails.js project with a mocha. I use trailpack-waterline to upload my models to ORM Waterline.

Following the tracks of the Docs , I created 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 is done without error.

But I just can’t create an instance of the model. Following the new User({...}) docs example new User({...}) , you need to create a new user object, but this code throws a User is not a constructor error. And not a single Waterline Docs example using User.create({...}) seems to work.

The listing of the user model shows that it consists of only two methods: [ 'getModelName', 'getTableName' ] .

How to instantiate a waterline model for unit testing?

+8
javascript unit-testing mocha waterline trailsjs
source share
1 answer

This is because global.app.models.User is your model definition, not the waterline model. This parameter is under global.app.orm.User , after which you can use User.create without any problems User.create

0
source share

All Articles