chaijs / chai-jquery

jQuery assertions for chai
MIT License
372 stars 69 forks source link

Not patching Chai using RequireJS #29

Closed davejacobs closed 11 years ago

davejacobs commented 11 years ago

I'm trying to get Chai/jQuery working with RequireJS, and I can't seem to get it to patch Chai. Specifically, I have the following in my runner.js file:

define(function(require) {
  var chai = require("chai"),
      mocha = require("mocha");

  require("chai_jquery");

  assert = chai.assert;
  should = chai.should();
  expect = chai.expect;

  mocha.setup("bdd");

  require(["../../spec/app_spec",
           "../../spec/app/views/login_layout_spec"], function() {
    mocha.run();
  });
});

And the following in my config.js file:

paths: {
  // ... Other paths
  chai: "../lib/chai",
  chai_jquery: "../lib/chai-jquery",
  mocha: "../lib/mocha"
},

shims: {
  mocha: { exports: "mocha" }
  // Have tried with and without this, which should be unnecessary:
  // chai_jquery: { deps: ["jquery", "chai"] }
}

When I run the specs, jQuery objects haven't been patched with the appropriate methods -- for example, attr. What am I doing wrong?

bendangelo commented 11 years ago

I just got this working myself. Make sure chai-jquery is required right after chai.