Posts

Showing posts with the label Jasmine

Automate JavaScript Testing with Grunt.js

So far we've learned how to test your JavaScript code with Jasmine and running them against Node.js and browsers with Karma . We've also got familiar with modular design patterns in JavaScript . And yet, somehow it seems that we're still missing one last puzzle piece connecting all the others, it's called Grunt.js . What is it? According to it's site: In one word: automation. The less work you have to do when performing repetitive tasks like minification , compilation, unit testing, linting , etc, the easier your job becomes. After you've configured it, a task runner can do most of that mundane work for you—and your team—with basically zero effort. Zero or not, there is a bit of effort in making everything play together, but no worry - we'll figure it out. So what's our plan? Write classes, which are both usable in Node.js, Require.js and global environment. Write Jasmine specs to test our code in both Chrome and Firefox Write Karma ...

Jasmine and Node.js

Following our last article about using Jasmine and Karma together, let's look how we streamline the testing of our server side code written in Node.js. To do this, we'll need to install jasmine-node package. npm install -g jasmine-node If you're not familiar with the tool, please read the JavaScript Developer Toolkit before proceeding any further. The installed version will only support Jasmine 1.3 version. In order to add the 2.0 support, you should install the branched version. npm install -g jasmine-node@2.0.0-beta4 Again as in previous article we'll be using the specs from our previous Jasmine article and the source code can be found in GitHub . After installing the correct version, we'll have to make our Player and Song classes as CommonJS modules. If you don't know how, please read the article about Modular Design Patterns in JavaScript . And of course requiring them in our specs: ... module.exports = Song; ... module.exports = Player; ...

Jasmine and Karma

Let's talk about testing again, and will surely again in the future :) Last time I introduced the JavaScript Testing with Jasmine and we ran a few specs, however it seemed some how half baked - you were required to create a special page and open it in the browser to see the results. I you wanted to check in various browsers, you should have iterated the same procedure on each browser again and again. This is not how we do things in 2014! We want to streamline the process! This is where Karma comes. It is built on Node.js and allows you to run the tests of your front end code automatically on various browsers. Installation In order to install Karma on your computer, run the following npm command. If you're not familiar with the tool, please read the JavaScript Developer Toolkit article first: npm install -g karma After you try to call karma though, you'll get unknown command error, which can be easily solved by installing karma command-line interface ( CLI )...

JavaScript Testing with Jasmine

For years, JavaScript developers checked their code by amm uhmm - exactly, they didn't. The QA, if there was one, tested the overall UI end to end. However no one really checked the code as it was accustomed with server side languages. Later testing frameworks started to emerge. QUnit  pioneered the domain, which was followed by Jasmine  and in the end Mocha appeared. All these framework matured with time and became standard in the industry. Nowadays, there is absolutely no excuse for JavaScript developer to write a code without writing the tests. Which one? As I've mentioned, currently there are three frameworks, which are mature enough to be considered by us. I personally prefer Jasmine over others, since it's already packaged with test double function  (spy) and assertion framework and offers fairly headless running. For those who prefer configuring different aspects and implementations of your testing framework should look at Mocha. Moreover have a look ...