I'm completely out of ideas as to what is going on here so hopefully someone can help.
Here is my script that I'm testing;
function MyFunc() {
this.test = 'hello world';
};
module.exports = MyFunc;
Here is my test;
var expect = require('chai').expect;
var MyFunc = require('../myfunc.js');
describe('MyFunc', function() {
it('test should equal to Hello World', function() {
var subject = new MyFunc;
expect(subject.test).to.eql('hello world');
});
})
When I run the test it fails and it gives me this message;
TypeError: MyFunc is not a function
I've simplified the code just to get my problem across, but I've tried several variations to no avail. I've spent quite a bit of time looking for similar issues with no joy (usually that means it's something stupid I'm doing. Lets hope).
I test my Angular code in a very similar way with no issues at all. I'm stumped!
Thanks for taking the time to read,
Anthony
Change var subject = new MyFunc
===> var subject = new MyFunc()
describe('MyFunc', function() { it('test should equal to Hello World', function() { var subject = new MyFunc(); expect(subject.test).to.eql('hello world'); }); })
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.