Skip to content

Commit

Permalink
Register all prop checks as methods
Browse files Browse the repository at this point in the history
This removes conflics when chai-jquery is registered
along another libraries like chai-enzyme

enzymejs/chai-enzyme#60
  • Loading branch information
eugenet8k committed Dec 9, 2017
1 parent e1c6697 commit ec07afe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion chai-jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
});

$.each(['visible', 'hidden', 'selected', 'checked', 'enabled', 'disabled'], function (i, attr) {
chai.Assertion.addProperty(attr, function () {
chai.Assertion.addMethod(attr, function () {
this.assert(
flag(this, 'object').is(':' + attr)
, 'expected #{this} to be ' + attr
Expand Down
48 changes: 24 additions & 24 deletions test/chai-jquery-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,22 +447,22 @@ describe("jQuery assertions", function(){
});

it("passes when the element is visible", function(){
visible.should.be.visible;
visible.should.be.visible();
});

it("passes negated when the element is hidden", function(){
hidden.should.not.be.visible;
hidden.should.not.be.visible();
});

it("fails when the element is hidden", function(){
(function(){
hidden.should.be.visible;
hidden.should.be.visible();
}).should.fail("expected " + inspect(hidden) + " to be visible");
});

it("fails negated when element is visible", function(){
(function(){
visible.should.not.be.visible;
visible.should.not.be.visible();
}).should.fail("expected " + inspect(visible) + " not to be visible");
});
});
Expand All @@ -480,22 +480,22 @@ describe("jQuery assertions", function(){
});

it("passes when the element is hidden", function(){
hidden.should.be.hidden;
hidden.should.be.hidden();
});

it("passes negated when the element is visible", function(){
visible.should.not.be.hidden;
visible.should.not.be.hidden();
});

it("fails when the element is visible", function(){
(function(){
visible.should.be.hidden;
visible.should.be.hidden();
}).should.fail("expected " + inspect(visible) + " to be hidden");
});

it("fails negated when element is hidden", function(){
(function(){
hidden.should.not.be.hidden;
hidden.should.not.be.hidden();
}).should.fail("expected " + inspect(hidden) + " not to be hidden");
});
});
Expand All @@ -505,22 +505,22 @@ describe("jQuery assertions", function(){
var unselected = $('<option></option>');

it("passes when the element is selected", function(){
selected.should.be.selected;
selected.should.be.selected();
});

it("passes negated when the element is not selected", function(){
unselected.should.not.be.selected;
unselected.should.not.be.selected();
});

it("fails when the element is not selected", function(){
(function(){
unselected.should.be.selected;
unselected.should.be.selected();
}).should.fail("expected " + inspect(unselected) + " to be selected");
});

it("fails negated when element is selected", function(){
(function(){
selected.should.not.be.selected;
selected.should.not.be.selected();
}).should.fail("expected " + inspect(selected) + " not to be selected");
});
});
Expand All @@ -530,22 +530,22 @@ describe("jQuery assertions", function(){
var unchecked = $('<input>');

it("passes when the element is checked", function(){
checked.should.be.checked;
checked.should.be.checked();
});

it("passes negated when the element is not checked", function(){
unchecked.should.not.be.checked;
unchecked.should.not.be.checked();
});

it("fails when the element is not checked", function(){
(function(){
unchecked.should.be.checked;
unchecked.should.be.checked();
}).should.fail("expected " + inspect(unchecked) + " to be checked");
});

it("fails negated when element is checked", function(){
(function(){
checked.should.not.be.checked;
checked.should.not.be.checked();
}).should.fail("expected " + inspect(checked) + " not to be checked");
});
});
Expand All @@ -555,22 +555,22 @@ describe("jQuery assertions", function(){
var enabled = $('<input>');

it("passes when the element is enabled", function(){
enabled.should.be.enabled;
enabled.should.be.enabled();
});

it("passes negated when the element is disabled", function(){
disabled.should.not.be.enabled;
disabled.should.not.be.enabled();
});

it("fails when the element is disabled", function(){
(function(){
disabled.should.be.enabled;
disabled.should.be.enabled();
}).should.fail("expected " + inspect(disabled) + " to be enabled");
});

it("fails negated when element is enabled", function(){
(function(){
enabled.should.not.be.enabled;
enabled.should.not.be.enabled();
}).should.fail("expected " + inspect(enabled) + " not to be enabled");
});
});
Expand All @@ -580,22 +580,22 @@ describe("jQuery assertions", function(){
var enabled = $('<input>');

it("passes when the element is disabled", function(){
disabled.should.be.disabled;
disabled.should.be.disabled();
});

it("passes negated when the element is enabled", function(){
enabled.should.not.be.disabled;
enabled.should.not.be.disabled();
});

it("fails when the element is enabled", function(){
(function(){
enabled.should.be.disabled;
enabled.should.be.disabled();
}).should.fail("expected " + inspect(enabled) + " to be disabled");
});

it("fails negated when element is disabled", function(){
(function(){
disabled.should.not.be.disabled;
disabled.should.not.be.disabled();
}).should.fail("expected " + inspect(disabled) + " not to be disabled");
});
});
Expand Down

0 comments on commit ec07afe

Please sign in to comment.