Monday, March 23, 2015

3/23/15 - Mocha and Karma

Today Finn and I worked on setting up our test suite.  We're using Mocha, which I like because it is syntactically very similar to rspec, the ruby test suite I used for NSFPatents2.  We're also using Karma--since Mocha runs on node.js, things like window and jQuery are undefined, and our javascript would of course throw errors because of this and cause our tests to fail.

Here's Finn's breakdown of how we got Mocha and Karma to work.

Karma is a wrapper for Mocha that allows the tests to run in an actual browser environment, so assumptions that are made in our code like 'there is a window we can add elements to' will be valid (node.js is a server, so it doesn't have any of that). Right now we are trying to figure out how to have our app.js and eventually other files accessible so that we can test them.

Also, I'm not sure exactly how Karma handles things, but I would imagine we need to set it to test in Firefox.  Fxpay, which I'm using as reference to try to set this stuff us, does this here in their Karma config file.  I think we'll also need to install this plugin for Karma (This page was also helpful).

I'm excited to start testing because I think it will give us a reason to really spend a lot of time improving the structure of our code. For example, methods like this are pretty much untestable in their current state. I'm thinking that we should have separate objects that handle page generation for each of our pages. I'm not sure how object inheritance works in javascript (or if it even exists) though.

1 comment:

  1. Great post! I like the cross link with Finn's blog, which saves you from having to repeat details he has already covered and shows just how well you are coordinating efforts. I'm also really glad you are working out an effective testing process. I plan on following behind you, but only *after* you've worked out the difficulties ;-)

    Regarding inheritance, JavaScript uses prototyping rather than the class inheritance you are used to with Ruby or Java. You will be able to accomplish what you want, but only after you wrap your head around the language.

    The Mozilla Developer Network provides a good place to start:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain

    ReplyDelete