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?
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 usingself.callbacks['error']('Path does not start with a slash');
. I changed it toself.emit('error', 'Path does not start with a slash');
Problem solved (for me).
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.
I had the same issue, thanks @John Doherty's answer, I discovered my problem:
It's a typo on
this.callback
, it should bethis.callbacks
:I know what code you are referring to. The problem is
Replace with:
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 theon
"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!