Seeking a JavaScript unit testing environment, I feel like I'm on a quest for the Holy Grail. The criteria are as follows:
- testing Requirejs AMD modules
- isolating each module by mocking out dependencies
- ability to test in-browser during development
- capability to test in a headless environment for continuous integration
Everything seems straightforward except for the aspect of headless mocking.
So far, I have experimented with JS-Test-Driver, Karma, and Phantomjs. For mocking purposes, I have utilized Squire and Isolate, along with an implementation from an answer here. Unfortunately, nothing seems to work quite right. The main issue that keeps cropping up is that the test framework completes before all tests have been run, mainly due to the mocks needing their own require()
dependencies.
Any assistance or guidance would be greatly appreciated!
[edit]
I have created a simple, functional Karma project on Github with some example mocked tests, using chai-expect as the assertion library. I will strive to add more comprehensive documentation, but if you are familiar with Karma, extending it should be fairly easy. Simply git clone
and then npm install
to get started.