GithubHelp home page GithubHelp logo

chai-jquery's People

Contributors

addbrick avatar aldraco avatar axelpale avatar bronzehedwick avatar charlierudolph avatar domenic avatar duncanbeevers avatar jamesmaroney avatar jfirebaugh avatar joliss avatar keithamus avatar khirakawa avatar kossnocorp avatar logicalparadox avatar mange avatar meeber avatar meyertee avatar spiralman avatar swbiggart avatar t1st3 avatar yangmillstheory avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chai-jquery's Issues

assertion for :focus

Would you find it useful to have a new assertion for focus (as per jQuery's focus selector)

In the end, we would get something like: expect('#mystuff').to.have.focus as a new assertion.

If it makes sense to you (notably @keithamus), I'd be happy to try a PR for that!

Potential failure message improvement

Hey guys!

Now expect(jQuery("div#section")).not.to.be.visible; fails with a message like this:

Uncaught AssertionError: expected { Object (0, 1, ...) } not to be visible

It seems to me that it would be an improvement to have the failure message mention the jQuery selector instead of { Object (0, 1, ...) } when it’s available. For example:

Uncaught AssertionError: expected 'div#section' not to be visible

What do you think?

How do I run the test suite?

Oh, this repo lives in the chaijs org namespace now? How cool.

I was just trying to run the test suite, but opening test/index.html in the browser fails, because it contains references to ../node_modules.

I think I'm missing something really obvious here. Could you please enlighten me how to set this up?

NPM package is outdated

NPM is serving up version 2.0. The last release version is 2.0.1, but that doesn't reflect the latest code assets from master.

Proposal: remove be matcher, rename have matcher

These two cause the only real issues I see with this library.
Any special thing you have to watch out for is a red flag to me.
Breaking other matchers should not be acceptable.
I agree with trying to stay close to the jQuery names but if that breaks things its not worth it.

be(selector) is unnecessary

  • match is an alias
  • selectors are predominantly class / id / other attributes which all have their own matchers
  • most other uses of the is function are all captured in other matchers (disabled, hidden, etc)

have(selector) can be renamed (most likely to descendants)
jQuery's description of has: Reduce the set of matched elements to those that have a descendant that matches the selector or DOM element.

expect($(".abc")).to.have.descendants(".def") 
// reads better than
expect($(".abc")).to.have(".def") 

`contain` silently passes for strings

Without chai-jquery, 'foo'.should.contain('bar') fails, but with it, it passes silently.

(I'll go and write up a failing test case when I figure out how to run the suite.)

Only first element is tested

I have noticed that only the first element which is passed to the expect function is tested for the expectation. Example:

it('should fail', function () {
    var divs = $('<div title="a"></div><div title="b"></div>');
    expect(divs).to.have.attr('title', 'a');
});

This test does not fail because only the first div is tested. Since jQuery usually performs operations for every selected element, this was surprise for me.

I don't think the current behaviour should be changed because otherwise it could happen that tests, which fail at the moment because an empty jQuery is passed to expect() would suddenly succeed. However, I think it would be convenient to introduce the each keyword which performs the expectation for every given element. Example:

it('should fail', function () {
    var divs = $('<div title="a"></div><div title="b"></div>');
    expect(divs).each.to.have.attr('title', 'a');
});

What do you think?

Publish new version to npm

I'd like to get my new changes using my favorite package manager :).

If you want me to handle npm releases, you can do

npm owner add domenic chai-jquery

Assert on the DOM node tag name

I would like to make sure that a DOM node is a <span> or an <a>. I can use .match("a") but I though there could exist something more specific (just like for .attr()).

Error: Cannot find module 'chai-jquery'

Is chai-query a library? I cannot seem to install it from npm registry for this legacy application I am trying to work with.

import _$ from "jquery";
import React from "react";
import ReactDOM from "react-dom";
import TestUtils from "react-dom/test-utils";
import jsdom from "jsdom";
import chai, { expect } from "chai";
import chaiJquery from "chai-jquery";
import { Provider } from "react-redux";
import { createStore } from "redux";
import reducers from "../src/reducers";

Make work in Node.js "virtual DOMs"

I want to use Chai-jQuery to do unit testing in Node.js with tmpvar/jsdom. I think there are a few different ways to do this, e.g. using coolaj86/node-jquery or using jsdom's native jQuerify. But in the end I think the trick is that they all give you a $ variable to play with.

So I think we need to inject this jQuery instance into Chai-jQuery. My proposal is to add a property to the module's exports, e.g. chaiJQuery.$ or chaiJQuery.jQuery. In the browser it can be set to the global jQuery, or to require("jquery"), respectively; in Node.js it can be left undefined by default. Then, internally, use that jQuery instance in all the instanceof jQuery checks.

You would also want to remove any references to jQuery that happen on module initialization (before the jQuery instance could be injected), of which there are currently two:

  1. Adding jQuery.fn.inspect: just hide this behind an if (chaiJQuery.jQuery).
  2. Using jQuery.each: write out the for loop, or even just use Array.prototype.forEach since Chai in general doesn't work great on pre-ES5 browsers.

Thoughts? Happy to submit a pull request for this if you're behind it.

overriding obj instanceof $

I would like to be able to control the hard-coded check on jQuery instances. What I'm referring to is this:

obj instanceof $

Why?
I have my own custom object which is what I pass to the expect method. It implements all of the chai-jquery methods (is, text, val, class, id, etc), and proxies those out to jQuery, but it itself is not an instance of jQuery.

It would be nice if we could refactor the instance check to a public overridable method, with the default being instanceof. Something like this perhaps:

if (instanceOfJquery(obj)) {
  this.assert(...)
} else {
  _super.apply(this, arguments);
}

Then I could just override that method and be on my merry way. =)

If AMD is available, install the plugin

If we're in an AMD environment, wouldn't it make sense to just install the plugin rather than return it? In other words, is there a use case where we require 'chai-jquery' but don't want it installed by default?

I would have expected this:

diff --git a/chai-jquery.js b/chai-jquery.js
index f29f2b1..aa8f693 100644
--- a/chai-jquery.js
+++ b/chai-jquery.js
@@ -5,10 +5,10 @@
     module.exports = chaiJquery;
   } else if (typeof define === "function" && define.amd) {
     // AMD
-    define(['jquery'], function ($) {
-      return function (chai, utils) {
+    define(['jquery','chai'], function ($,chai) {
+      chai.use(function (chai, utils) {
         return chaiJquery(chai, utils, $);
-      };
+      });
     });
   } else {
     // Other environment (usually <script> tag): plug in to global chai instanc

Improve assertion message for data() chainer

The current assertion message for the data chainer is something to the effect of

expected { ... }[ not] to have property propertyName[ of value]"

It would be a great improvement to mention that it concerns a data(set) property instead of a "regular" property, so I'd propose to change the message to:

expected { ... }[ not] to have data property propertyName[ of value]"

or

expected { ... }[ not] to have dataset property propertyName[ of value]"

Chai length() assertion doesn't work.

The following assertion (which works in Chai without the jQuery plugin) throws an exception ) when chai-jquery is included:

(['foo','bar']).should.have.length(2);

In Chrome the exception is: "TypeError: Property 'length' of object [object Function] is not a function"

I believe I have a fix (I'll submit a pull request in a minute).

chai and jquery as peerDependencies

Have you consider using

"devDependencies": {
  "mocha": "1",
  "mocha-phantomjs": "3"
}, 
"peerDependencies": {
  "chai": "1",
  "jquery": "2"
}

To enable npm to manage your dependencies, and share the dependencies lifecicle with other peer projects (like karma plugins)?

Should `contain` test for containment in .text().whitespaceNormalize()?

Capybara in version 2.0 has switched from using :contains to testing for whitespace-normalized containment, and this works much better in practice. I wonder if we should do the same?

In JavaScript, the logic is essentially like this:

whitespaceNormalize(selection.text()).indexOf(whitespaceNormalize(expectedString)) !== -1

The change in Capybara has eliminated a lot of headache with :contains not working due to extra whitespace between words, because the whitespace can easily change as you refactor templates.

So I wonder if chai-jquery should do the same?

Cannot use exist() as a function

Chai's API allows exist to be use either as a property, or as a function: expect(foo).to.exist();. However, when using chai-jquery (on non-jQuery object) only the former option can be used; when trying to call exists(), you can an "object is not a function" error.

Add IE support

Few notes concerning IE.

  • IE9:
    Tests are running. Most of them are failing because should.have.X(), expect.to.be.X() doesn't work.
  • IE7, IE8:
    Not capable of running tests.

Release 1.0.0

New version of chai is released in npm, but chai jquery is still old (so I can update versions).

css() method won't take hex

Hi Everyone,

I noticed that when I try to use a hex color value such as #ff0000 that it won't pass the test. However, if I use rgb() it will pass the text. For example:
expect($('div')).to.have.css('color', '#ff0000'); ---> will NOT pass
expect($('div')).to.have.css('color', 'rgb(255, 0, 0)');" --> WILL pass

I am writing the tests in the following json doc:
https://github.com/BlueOceanView/freecodecamp/blob/master/seed_data/coursewares.json#L78

I am wondering why this is so?

Thanks!
Julie (a.k.a. BlueOceanView)

bower.json

I would like to download chai-jquery using bower but I don't see bower.json file in repository. Still I can find (and download) it on bower.io: http://bower.io/search/?q=chai-jquery.

How it's possible? Can we add bower.json to repository?

I ask because I want to use chai-jquery in my rails project through Rails Assets and it requires bower.json:

You can now require BOWER_PACKAGE_NAME in your stylesheets and JavaScript files—all assets exposed as main in bower.json will be automatically included.

Official `length` workaround doesn't work

About to dig deeper into this, but the be.of.length(x) workaround for have.length(x) no longer seems to work.

I just cloned fresh, npm installed and added a single test for

$('<div></div>').should.be.of.length(1);

And get the following failure:

TypeError: Property 'length' of object function (selector) {
    var obj = flag(this, 'object');
    if (obj instanceof $) {
      this.assert(
          obj.is(selector)
        , 'expected #{this} to be #{exp}'
        , 'expected #{this} not to be #{exp}'
        , selector
      );
    } else {
      _super.apply(this, arguments);
    }
  } is not a function
at Context.<anonymous> (file://localhost/Users/chris/dev/chai-jquery/test/chai-jquery-spec.js:604:37)
at Test.Runnable.run (file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4039:32)
at Runner.runTest (file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4404:10)
at file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4450:12
at next (file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4330:14)
at file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4339:7
at next (file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4287:23)
at file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:4307:5
at timeslice (file://localhost/Users/chris/dev/chai-jquery/node_modules/mocha/mocha.js:5279:29)

I get a different error in Safari:

'1' is not a function (evaluating 'subject.should.be.of.length(1)')

I suppose it's possible there's something wrong with my setup, but I don't see what it could be...

Does not allow length checks on jQuery objects

We may need to test that an exact number of elements match a selector, and it seems chai-jquery breaks previously methods of doing this. Previously, we were doing:

expect(el.find('.modal-footer button')).to.have.length(2);

But this fails when chai-jquery is included:

'1' is not a function (evaluating 'expect(el.find('.modal-footer button')).to.have.length(2)')

In order to get our tests to run, we had to change it to:

expect(el.find('.modal-footer button').length).to.equal(2);

Is there a better recommended way of accomplishing this using chai-jquery? have is not sufficient as it only tests if at least one descendant is present.

doesn't work unless you include it after jquery

The readme instruction says all you have to do is include chai-jquery after chai
but you also have to include jquery before that.

Was just a little confusing as to why it didn't work.
I went to use chai-jq instead which just worked.

.to.have.text() and friends should report actual text

sinon-chai does a really useful thing in error reports where when an assertion for the arguments of a function call fails, the library will print out the arguments that the function was actually called with. It would be really nice if sinon-jquery had similar behavior with regard to things like .to.have.text()

Test suite failure

On master, I'm getting 78 passes, 14 failures on the test suite (test/index.html):

be
preserves existing behavior on non-jQuery objects
passes when the selection matches the given selector
TypeError: Property 'be' of object #<Assertion> is not a function
    at Context.<anonymous> (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/test/chai-jquery-spec.js:493:22)
    at Test.run (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3001:32)
    at Runner.runTest (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3305:10)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3349:12
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3233:14)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3242:7
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3192:23)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3210:5
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:4022:44
passes negated when the selection does not match the given selector
TypeError: Property 'be' of object #<Assertion> is not a function
    at Context.<anonymous> (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/test/chai-jquery-spec.js:497:26)
    at Test.run (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3001:32)
    at Runner.runTest (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3305:10)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3349:12
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3233:14)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3242:7
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3192:23)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3210:5
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:4022:44
fails when the selection does not match the given selector
expected [Function] to fail, but it threw [TypeError: Property 'be' of object #<Assertion> is not a function]
fails negated when the selection matches the given selector
expected [Function] to fail, but it threw [TypeError: Property 'be' of object #<Assertion> is not a function]
contain
preserves existing behavior on non-jQuery objects
TypeError: Property 'contain' of object #<Assertion> is not a function
    at Context.<anonymous> (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/test/chai-jquery-spec.js:515:31)
    at Test.run (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3001:32)
    at Runner.runTest (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3305:10)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3349:12
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3233:14)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3242:7
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3192:23)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3210:5
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:4022:44
passes when the selection contains the given text
TypeError: Property 'contain' of object #<Assertion> is not a function
    at Context.<anonymous> (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/test/chai-jquery-spec.js:522:22)
    at Test.run (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3001:32)
    at Runner.runTest (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3305:10)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3349:12
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3233:14)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3242:7
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3192:23)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3210:5
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:4022:44
passes negated when the selection does not contain the given text
TypeError: Property 'contain' of object #<Assertion> is not a function
    at Context.<anonymous> (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/test/chai-jquery-spec.js:526:26)
    at Test.run (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3001:32)
    at Runner.runTest (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3305:10)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3349:12
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3233:14)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3242:7
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3192:23)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3210:5
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:4022:44
fails when the selection does not contain the given text
expected [Function] to fail, but it threw [TypeError: Property 'contain' of object #<Assertion> is not a function]
fails negated when the selection contains the given text
expected [Function] to fail, but it threw [TypeError: Property 'contain' of object #<Assertion> is not a function]
handles quotes
TypeError: Property 'contain' of object #<Assertion> is not a function
    at Context.<anonymous> (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/test/chai-jquery-spec.js:542:38)
    at Test.run (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3001:32)
    at Runner.runTest (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3305:10)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3349:12
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3233:14)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3242:7
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3192:23)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3210:5
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:4022:44
have
preserves existing behavior on non-jQuery objects
passes when the selection has the given selector
TypeError: Property 'have' of object #<Assertion> is not a function
    at Context.<anonymous> (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/test/chai-jquery-spec.js:555:22)
    at Test.run (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3001:32)
    at Runner.runTest (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3305:10)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3349:12
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3233:14)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3242:7
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3192:23)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3210:5
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:4022:44
passes negated when the selection does not have the given selector
TypeError: Property 'have' of object #<Assertion> is not a function
    at Context.<anonymous> (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/test/chai-jquery-spec.js:559:26)
    at Test.run (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3001:32)
    at Runner.runTest (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3305:10)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3349:12
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3233:14)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3242:7
    at next (file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3192:23)
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:3210:5
    at file://localhost/Volumes/ubuntu/src/vso/vendor/chai-jquery/node_modules/mocha/mocha.js:4022:44
fails when the selection does not have the given selector
expected [Function] to fail, but it threw [TypeError: Property 'have' of object #<Assertion> is not a function]
fails negated when the selection has the given selector
expected [Function] to fail, but it threw [TypeError: Property 'have' of object #<Assertion> is not a function]

Is this just my setup, or is it actually failing?

Parity with jasmine-jquery

As part of moving away from a reliance on Jasmine, replacing jasmine-jquery is going to be a factor for many people. Is this plugin aiming to eventually have feature-parity with jasmine-jquery?

Overriding '.be' causes incorrect usage to be silently ignored

Let's say you are new to Chai or you just forget all the matchers and how they work. You might think that this is how you check that something is the same as something else:

expect(1 + 1).to.be(2);

Without chai-jquery loaded this throws an error: TypeError: Property 'be' of object #<Assertion> is not a function. However, when chai-jquery is loaded and you run this again you will get no exception. This seems to be because of the be override that can be called as a function. The trouble is that when the object being asserted against isn't a jQuery object the assertion is simply a no-op.

I'm not sure how to fix this. My inclination is to simply remove the be override and tell people to use match, though that'd obviously break backward compatibility. If there's some way to determine that it is being called in the manner above and to throw an exception that would be best.

Make AMD version depend on jQuery.

When using AMD, instead of using the jQuery global, add it to your dependencies array. This way people loading jQuery via AMD don't have to load jQuery manually; it gets auto-loaded as a dependency of Chai-jQuery.

In my case, the first modules we load are Chai, Sinon-Chai, and Chai-jQuery, so we can wire up the chai.use calls. This breaks, however, unless we also load jQuery in this initial set, since Chai-jQuery uses the jQuery global.

Add ability to specify jQuery object

At the moment chai-jquery assumes jQuery is jQuery on the window object, but this isn't always the case, e.g. Ember has Ember.$. Allow an option to specify the jQuery object.

Not patching Chai using RequireJS

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.