No output from jasmine-node

£可爱£侵袭症+ 提交于 2019-12-22 10:53:42

问题


I'm new to JavaScript, Node.js and jasmine. I'm trying to run a test from the book "The Node Craftsman Book", FilesizeWatcher. I've created the package.json file and run "npm install", thus installing jasmine-node locally to the project. When I run jasmine-node on the spec file I see only output from console.log but nothing from jasmine. I can see from console.log statements that calls to jasmine (e.g. expect(err).toBe("Path does not start with a slash");) are made, but there is no output.

Any idea of where i should start to find an error?


回答1:


I know what code you are referring to. The problem is

watcher.on('grew', function(gain) { 
 expect(gain).toBe(5);
 done();
});

Replace with:

watcher.callbacks['grew'] = function(gain) { 
 expect(gain).toBe(5);
 done();
}

The core of the problem seems to be that the test is written to run on different code. From a pure JS point of view, watcher object does not have the on "key" and therefore, by simply reading the code, I would not expect it to work. I am new to Node too so, at first, I simply assumed that it would work. I think the lesson there is: JS is JS and nothing node does with it changes that. I found a much better introduction in a book called "Eloquent Javascript". Good luck!




回答2:


I had the same issue and discovered that by adding the switch:

--captureExceptions

Mentioned by @Charminbear in the comments above, jasmine-node produced a list of errors in my scripts. Fixing these resolved the issue.




回答3:


I managed to get this to work after realising a few errors on my part.

Firstly, I still had self.callbacks = {}; in my code. I removed this. Secondly, I was still using self.callbacks['error']('Path does not start with a slash');. I changed it to self.emit('error', 'Path does not start with a slash');

Problem solved (for me).




回答4:


I had the same issue, thanks @John Doherty's answer, I discovered my problem:

self.callbacks = {};
//...
FilesizeWatcher.prototype.on = function(eventType, callback) {
    this.callback[eventType] = callback;
};

It's a typo on this.callback, it should be this.callbacks:

FilesizeWatcher.prototype.on = function(eventType, callback) {
    this.callbacks[eventType] = callback;
};


来源:https://stackoverflow.com/questions/28855202/no-output-from-jasmine-node

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!