Skip to content
jejacks0n edited this page Jun 16, 2013 · 9 revisions

To get setup for QUnit you'll need to configure your suites. Since QUnit tests aren't considered specs, we need to adjust the path to point to test/javascripts. You should make a test/javascripts path and then change your suite(s).

config/initializers/teaspoon.rb

Teaspoon.setup do |config|

  config.suite do |suite|
    suite.matcher = "test/javascripts/**/*_test.{js,js.coffee,coffee}"
    suite.javascripts = ["teaspoon/qunit"]
    suite.helper = "test_helper"
  end

end

Example Test

//= require jquery
module("My great feature");

test("will change the world", 2, function() {
  ok(true, "Passing is true");
  ok(typeof(jQuery) !== "undefined");
});

Example Fixture Usage

fixture.preload("fixture.html", "fixture.json");

module("Using fixtures", {
  setup: function() {
    fixture.set("<h2>Another Title</h2>");
    this.fixtures = fixture.load("fixture.html", "fixture.json", true);
  }
});

test("loads fixtures", function() {
  ok(document.getElementById("fixture_view").tagName === "DIV", "is in the dom");
  ok(this.fixtures[0] === fixture.el, "has return values for the el");
  ok(this.fixtures[1].title === fixture.json[0].title, "has return values for json");
});