Skip to content

All of my node_modules return undefined #311

@mattdell

Description

@mattdell

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions