Really struggling with this.
Test file is users.spec.js
import testHelper from '../test-helper';
const { chai, expect, baseUrl } = testHelper;
describe('users endpoint', () => {
it('should get a response', (done) => {
chai.request(baseUrl)
.get('/users')
.end((err, res) => {
expect(res).to.have.status(200);
done();
});
});
});
testHelper calls a file user.ts, which at the top says...
import mongoose from 'mongoose';
export interface IUserModel extends mongoose.Document {
When I run ts-node I get the following error
> mocha --opts tests/mocha.opts
/Users/mdell/Play/Repos/server/src/models/user.ts:23
const userSchema = new mongoose.Schema({
^
TypeError: Cannot read property 'Schema' of undefined
The same thing happens if I try to call lodash in the same place.
import _ from 'lodash';
console.log('_ is', _);
console.log(_.sum([1, 2]));
> mocha --opts tests/mocha.opts
_ is undefined
/Users/mdell/Play/Repos/server/src/models/user.ts:4
console.log(_.sum([1, 2]));
^
TypeError: Cannot read property 'sum' of undefined
So it seems like tests that call files that call node_modules can't be run. What am I missing?
Really struggling with this.
Test file is users.spec.js
testHelper calls a file user.ts, which at the top says...
When I run ts-node I get the following error
The same thing happens if I try to call lodash in the same place.
So it seems like tests that call files that call node_modules can't be run. What am I missing?