chaijs / chai-jquery Goto Github PK
View Code? Open in Web Editor NEWjQuery assertions for chai
License: MIT License
jQuery assertions for chai
License: MIT License
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!
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?
It is in master though, and it's documented in README.
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 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.
Would it be possible to publish a version (with #73) to npm?
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
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")
Essentially, once you do a not assertion (expect($div).to.not.contain('.blah')
) you cannot chain it with a truthy
expect($div).to.not.contain('.blah').to.contain('.foo')
-> Error: Expected $div to NOT contain '.foo'
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.)
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?
looks like they changed this.obj
to this._obj
, or at least from what i can tell.
https://github.com/chaijs/chai-jquery#usage
You do not need to include via script
tag to use in your code if using modules https://github.com/chaijs/chai-jquery/blob/master/chai-jquery.js#L2-L13
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
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()
).
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";
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:
jQuery.fn.inspect
: just hide this behind an if (chaiJQuery.jQuery)
.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.
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 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
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]"
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).
Check this out: http://jsfiddle.net/rafmagana/V34cb/1/
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)?
You docs suggest that it uses a :selected
psuedoclass selector - however, I can't see that :selected
is actually a psuedoclass. https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes#input_pseudo-classes
Essentially what I'm wanting to use the is.selected
assertion on, is checking that an element with the role tab
has aria-selected="true"
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?
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.
Few notes concerning IE.
New version of chai is released in npm, but chai jquery is still old (so I can update versions).
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)
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.
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 install
ed 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...
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.
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.
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()
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?
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?
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.
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.
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.
Perhaps similar to #30, I'm experiencing an issue with the following spec:
expect($('.foo')).to.have('h1');
TypeError: '[object Object]' is not a function (evaluating 'expect($('.foo')).to.have('h1')')
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?
We have a set of different matchers, like disabled, checked, visible, hidden, etc. - https://github.com/chaijs/chai-jquery/blob/master/chai-jquery.js#L142
All of them match to jquery's .is(":"+matcher).
Can we add "enabled" as opposite to "disabled" to avoid .should.not.be.disabled
and write .should.be.enabled
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.