jasmine-like fixtures without testing framework dependencies
Last updated 6 years ago by badunk .
Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install js-fixtures 
SYNC missed versions from official npm registry.


The fixtures module allows you to load HTML content to be used by your tests. Try using this in conjunction with a powerful assertion library such as chai-jquery.

The code was completely refactored from the awesome jasmine-jquery with all jasmine and jquery dependencies removed, specs written with Chai + Mocha, and using an iframe implementation as a sandbox. This allows the fixtures to be more portable and minimizes side effects with the test runner.


npm install js-fixtures // if you use npm
bower install fixtures // or if you prefer bower

then within your test runner:

<script src="fixtures.js"></script>

// or if you prefer AMD:
define(['fixtures'], function(fixtures){


Use fixtures.load('your-fixture.html') in your specs. Fixtures will load from /spec/javascripts/fixtures/your-fixture.html (see below to change this path). Once that is setup, you should be able to write specs that look like this:

describe('my jquery plugin', function(){
    var $$;
        $$ = fixtures.window().jQuery; // access the jquery instance from within the fixtures context
    it('it throws a lot of pizzazz on the screen', function(){
        // etc.. etc..
        fixtures.cleanUp(); // cleans up the fixture for the next test


Your fixture is being loaded into an iframe container that is automatically added to the DOM. Fixtures are internally cached, so you can load the same fixture file in several tests without penalty to your test suite's speed.

Several methods for loading fixtures are provided:

  • load(fixtureUrl[, fixtureUrl, ...], cb)
    • Loads fixture(s) from one or more files and automatically appends them to the DOM (to the fixtures container).
    • If cb is provided, it will fire upon iframe ready
  • set(html)
    • Same as load except you may load markup directly without specifying a path
  • sandbox(jsObject)
    • Creates a quick fixture from the js object you provide (ex. sandbox({id: 'foo-fixture', class: 'cool'}) )
  • read(fixtureUrl[, fixtureUrl, ...])
    • Loads fixture(s) from one or more files but instead of appending them to the DOM returns them as a string (useful in combination with set if you want to use a templating engine).
  • cache(fixtureUrl[, fixtureUrl, ...])
    • Pre-loads fixture(s) from one or more files and stores them into cache, without returning them or appending them to the DOM.

Additionally, two clean up methods are provided:

  • clearCache()
    • purges internal cache
  • cleanUp()
    • cleans-up fixtures container

Finally, there are two convenience methods to access the contents of the sandboxed iframe:

  • body
    • returns the html contents of the body. Use it to assert various values on the body of the iframe DOM.
  • window
    • returns the global window reference of the iframe, giving you the ability to use the global variables injected into that context.


  • fixtures.containerId
    • change the ID of the iframe that gets injected into the page
  • fixtures.path
  • change the path to look for fixtures (default: spec/javascripts/fixtures)

Executing Tests

Do an npm install to grab the test dependencies. Then point your browser to the test/index.html file.

Current Tags

  • 1.5.3                                ...           latest (6 years ago)

10 Versions

  • 1.5.3                                ...           6 years ago
  • 1.5.1                                ...           7 years ago
  • 1.5.0                                ...           7 years ago
  • 1.4.0                                ...           7 years ago
  • 1.3.1                                ...           7 years ago
  • 1.2.1                                ...           7 years ago
  • 1.2.0                                ...           7 years ago
  • 1.1.1                                ...           8 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.0                                ...           8 years ago
Maintainers (1)
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 4
Dependencies (1)
Dev Dependencies (3)
Dependents (0)

Copyright 2014 - 2017 © taobao.org |