jspm / github

Github Location Service
16 stars 43 forks source link

Mocha - testing files with dependancies #105

Closed linnett closed 8 years ago

linnett commented 8 years ago

I've got a couple of issues with unit testing js files.

First error: If the js file I am testing has no dependancies, it's working fine. However, when there are imports at the top, it does not work and throws an error saying it cannot find the file:

Error: Cannot find module 'myModule'

Do I somehow need to link the jspm.config file to the process and if so, how?

Second error: When I hard code the dependancy link to the file, I'm getting a syntax error that I wouldn't usually get when testing ES6 files:

constructor(options = {}) {
                      ^
SyntaxError: Unexpected token =

Do I need to do something to tell it my dependancies are ES6?

I am running the following from the command line: mocha <test filename here> --compilers js:babel-register.

The top of my test file looks like this:

import 'jsdom-global/register';
import chai from 'chai';
import MyModule from './MyModule';

const expect = chai.expect;

describe('MyModule', function() {

I am using "babel-register": "^6.11.6". Thanks for any help you can provide.