Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Using angular/di.js in a babel runtime gives error #103

Open
@dmtrs

Description

@dmtrs

My setup is babel v5.4.3 and mocha testing suite and I am trying to use di ^2.0.0-pre-14.

I have a require hook for my tests that looks like:

require("babel/register")({
    stage: 0
});

I have created a a file names src/rest.js that looks like this (request-promise):

import {Inject} from 'di';
import {default as Request} from 'request-promise';

@Inject(Request)
export class Rest {
    constructor(request) {
        this.request = request;
    }
}

following my src/rest.test.js looks like this:

import { Injector } from "di";
import { Rest } from "./rest";
import { should } from "chai";
should();

describe('Rest', function(){
    var injector = new Injector([]);
    describe('#constructor()', function(){
        it('should x', function(){ })
    })
})

when running the test I get the following error:

./node_modules/mocha/bin/mocha --require babelhook.js src/rest.test.js

/Users/dmtrs/code/sc.io/node_modules/di/dist/cjs/annotations.js:12
  this.tokens = tokens;
              ^
TypeError: Cannot set property 'tokens' of undefined
    at Inject (/Users/dmtrs/code/sc.io/node_modules/di/dist/cjs/annotations.js:12:15)
    at /Users/dmtrs/code/sc.io/src/rest.js:1:15
    at Object.<anonymous> (/Users/dmtrs/code/sc.io/src/rest.js:5:18)
    at Module._compile (module.js:456:26)
    at normalLoader (/Users/dmtrs/code/sc.io/node_modules/babel/node_modules/babel-core/lib/babel/api/register/node.js:150:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/dmtrs/code/sc.io/node_modules/babel/node_modules/babel-core/lib/babel/api/register/node.js:163:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/dmtrs/code/sc.io/src/rest.test.js:1:30)
    at Module._compile (module.js:456:26)
    at normalLoader (/Users/dmtrs/code/sc.io/node_modules/babel/node_modules/babel-core/lib/babel/api/register/node.js:150:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/dmtrs/code/sc.io/node_modules/babel/node_modules/babel-core/lib/babel/api/register/node.js:163:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at /Users/dmtrs/code/sc.io/node_modules/mocha/lib/mocha.js:192:27
    at Array.forEach (native)
    at Mocha.loadFiles (/Users/dmtrs/code/sc.io/node_modules/mocha/lib/mocha.js:189:14)
    at Mocha.run (/Users/dmtrs/code/sc.io/node_modules/mocha/lib/mocha.js:422:31)
    at Object.<anonymous> (/Users/dmtrs/code/sc.io/node_modules/mocha/bin/_mocha:398:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions