Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mocha-compatible fixtures support

I am looking to convert from Jasmine tests to Mocha tests because of its ability to do Before(all), its reporting capabilities, and its support for coffeescript.

One thing I haven't been able to find is whether Mocha (or in conjunction with a compatible assertion library) supports fixtures like jasmine-jquery does (https://github.com/velesin/jasmine-jquery). Does such functionality exist for Mocha?

I'm trying to test some in-browser code (so I will be running it with the html test runner) that manipulates the DOM. I don't wish to use zombiejs because I'd prefer to run it within the environment I'm testing in.

Edit: Just for reference, while searching for a solution, I came across using grunt + mocha with a phantomjs implementation. This also doesn't work for my case as I'd like to use a custom version of webkit.

like image 673
badunk Avatar asked Jun 13 '12 21:06

badunk


Video Answer


1 Answers

From what I've been able to figure out, the answer is no. This is probably due to the fact that Mocha was first meant to support node.js. In node, the notion of fixtures in jasmine-jquery doesn't exist because a DOM/browser doesn't exist.

Looking at the fixtures support for the jasmine-jquery plugin, I realize now that is may not be so difficult to build this functionality myself. The basic mechanism is to use jQuery to add an external template to the DOM, while retaining the references to it so that cleanup and caching is possible.

I will update this answer if I decide to release something on github

Edit: here it is - https://github.com/badunk/js-fixtures. The code and specs were essentially copied from jasmine-jquery with the dependencies removed.

like image 192
badunk Avatar answered Nov 03 '22 00:11

badunk