简体   繁体   English

没有来自jasmine-node的输出

[英]No output from jasmine-node

I'm new to JavaScript, Node.js and jasmine. 我是JavaScript,Node.js和jasmine的新手。 I'm trying to run a test from the book "The Node Craftsman Book", FilesizeWatcher. 我正在尝试从“节点工匠书”,FilesizeWatcher这本书中进行测试。 I've created the package.json file and run "npm install", thus installing jasmine-node locally to the project. 我创建了package.json文件并运行“npm install”,从而在本地安装jasmine-node到项目中。 When I run jasmine-node on the spec file I see only output from console.log but nothing from jasmine. 当我在spec文件上运行jasmine-node时,我只看到来自console.log的输出,但是没有来自jasmine的输出。 I can see from console.log statements that calls to jasmine (eg expect(err).toBe("Path does not start with a slash");) are made, but there is no output. 我可以从调用jasmine的console.log语句中看到(例如expect(err).toBe(“Path不以斜杠开头”);),但是没有输出。

Any idea of where i should start to find an error? 知道我应该从哪里开始发现错误吗?

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. 从纯JS的角度来看, watcher对象没有on “key”,因此,通过简单地阅读代码,我不希望它工作。 I am new to Node too so, at first, I simply assumed that it would work. 我也是Node的新手,一开始,我只是假设它会起作用。 I think the lesson there is: JS is JS and nothing node does with it changes that. 我认为那里的教训是:JS是JS,没有任何节点可以改变它。 I found a much better introduction in a book called "Eloquent Javascript". 我在一本名为“Eloquent Javascript”的书中找到了更好的介绍。 Good luck! 祝好运!

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. @Charminbear在上面的评论中提到,jasmine-node在我的脚本中产生了错误列表。 Fixing these resolved the issue. 修复这些解决了这个问题。

I managed to get this to work after realising a few errors on my part. 在我意识到一些错误后,我设法让这个工作。

Firstly, I still had self.callbacks = {}; 首先,我仍然有self.callbacks = {}; in my code. 在我的代码中。 I removed this. 我删除了这个。 Secondly, I was still using self.callbacks['error']('Path does not start with a slash'); 其次,我还在使用self.callbacks['error']('Path does not start with a slash'); . I changed it to self.emit('error', 'Path does not start with a slash'); 我将它改为self.emit('error', 'Path does not start with a slash');

Problem solved (for me). 问题解决了(对我来说)。

I had the same issue, thanks @John Doherty's answer, I discovered my problem: 我有同样的问题,谢谢@John Doherty的回答,我发现了我的问题:

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

It's a typo on this.callback , it should be this.callbacks : 这是this.callback的拼写错误,应该是this.callbacks

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM