Writing tests for a NodeJS app with Jasmine in Typescript

pascal.brokmeier
Jun 16, 2017 · 1 min read

Run down: Don’t use this, it’s too old: https://github.com/mhevery/jasmine-node

Just run

npm install --save-dev jasmine @types/jasmine nodemon

add the code below to a file calledjasmine.json

{
"spec_dir": "dist",
"spec_files": [
"**/*[sP]pec.js"
],
"stopSpecOnExpectationFailure": true
}

then add this line to your package json

“test”: “node_modules/nodemon/bin/nodemon.js -w dist ./node_modules/.bin/jasmine — config=jasmine.json”,

and make sure you have your tsc compiler set to output its results in the dist folder. Now every time the files compile to javascript, jasmine picks them up and runs your tests. This way you can continue developing normally with your workflow. I for example use this to keep my workflow running quickly (in package.json)

"watch": "node_modules/concurrently/src/main.js -k -p \"[{name}]\" -n \"TypeScript,Node\" -c \"yellow.bold,cyan.bold,green.bold\" \"npm run watch-ts\" \"node_modules/nodemon/bin/nodemon.js --inspect --delay 500ms dist/app/index.js\"",

with the tsconfig.json like so

{
"include": [
"src/**/*"
],
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"sourceMap": true,
"outDir": "./dist",
"rootDir": "./src",
"removeComments": false
}
}

Hope it helps ☺

curiouscaloo

Anything about technology and where our society and technology is heading towards

pascal.brokmeier

Written by

Software Developer, Tech enthusiast, student, board sports and food lover

curiouscaloo

Anything about technology and where our society and technology is heading towards

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade