Sunday, 16 April 2017

loading dependent of a dependent JS file

I have a code that will run on browsers. I am test cases for those in mocha. But problem I am facing:

parent.js

    function EntityAbstract() {

    this.$Ver = '';
}
    EntityAbstract.method('setVer', function($Ver) {
        this.$Ver = $Ver;
});

child.js

    function Note($Id, $Text) {
    this.$Id = $Id;
    this.$Text = $Text;
}

Note.inherits(EntityAbstract);

The above code works fine when I include file in html using

<script type="text/javascript" src="app/scripts/Structure/parent.js"></script>
<script type="text/javascript" src="app/scripts/Structure/child.js"></script>

Now, while I am trying to write test case for child.js using mocha in node.js environment.

require('node-import');
var entity = imports('src/app/scripts/Structure/parent');
var note = imports('src/app/scripts/Structure/child');

It throws error while running test file in mocha.

 ReferenceError: EntityAbstract is not defined at Node.inherits(EntityAbstract)

Note: I cannot do changes in child.js which browser doesn't support.



via Samirul

No comments:

Post a Comment