Skip to content
This repository has been archived by the owner on May 27, 2018. It is now read-only.

Commit

Permalink
Merge pull request #6 from xiongchiamiov/hidden-is-hidden
Browse files Browse the repository at this point in the history
Hidden is hidden
  • Loading branch information
jeffwatkins committed Feb 5, 2013
2 parents 38e0c0a + 2c4b799 commit 4ab5ff8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.markdown
Expand Up @@ -118,13 +118,13 @@ jasmine-dom provides following custom matchers (in alphabetical order):
expect(node).toBeChecked()
- `toBeEmpty()`: Tests whether the node is empty. A node is only empty if it has no child nodes.
- `toBeHidden()`: Tests whether the node is hidden. A node is considered hidden if both its `offsetWidth` and `offsetHeight` are 0. This may be caused by a display value of `none` either on the node or an ancestor node, or because the size of this node has been explicitly set to 0x0.
- `toBeHidden()`: Tests whether the node is hidden. A node is considered hidden if both its `offsetWidth` and `offsetHeight` are 0, or if the `visibility` CSS attribute is set to `hidden`. This may be caused by a display value of `none` either on the node or an ancestor node, or because the size of this node has been explicitly set to 0x0.
- `toBeSelected()`: For nodes with a selected attribute, this matcher tests whether the attribute is set to `true`.

var node= sandbox('<option selected="selected"></option>');
expect(node).toBeSelected()
- `toBeVisible()`: This matcher is the inverse of `toBeHidden`. If a node has a dimensions other than 0, it is visible.
- `toBeVisible()`: This matcher is the inverse of `toBeHidden`. If a node has a dimensions other than 0 and the CSS attribute `visibility` is not set to `hidden`, it is visible.

- `toContain(selector)`: Tests whether this node contains nodes that match the selector.

Expand Down
5 changes: 3 additions & 2 deletions lib/jasmine-dom-matchers.js
Expand Up @@ -93,12 +93,13 @@ jasmine.DOM.matchers = {};

toBeVisible: function()
{
return (this.actual.offsetWidth!==0 || this.actual.offsetHeight!==0);
return !(matchers['toBeHidden'].apply(this, arguments));
},

toBeHidden: function()
{
return (0===this.actual.offsetWidth && 0===this.actual.offsetHeight);
return ((0===this.actual.offsetWidth && 0===this.actual.offsetHeight)
|| this.actual.style.visibility == 'hidden');
},

toBeSelected: function()
Expand Down
23 changes: 20 additions & 3 deletions spec/suites/jasmine-dom_spec.js
Expand Up @@ -442,19 +442,36 @@ describe("DOM matchers", function() {
expect(findSandbox()).toBeVisible();
});

it("should pass negated on non-displayed element", function() {
var node=sandbox();
node.style.display='none';
setFixtures(node);
expect(findSandbox()).not.toBeVisible();
});

it("should pass negated on hidden element", function() {
var node=sandbox();
node.style.visibility='hidden';
setFixtures(node);
expect(findSandbox()).not.toBeVisible();
});
});

describe("toBeHidden", function() {
it("should pass on hidden element", function() {
var node= sandbox();
it("should pass on non-displayed element", function() {
var node=sandbox();
node.style.display='none';
setFixtures(node);
expect(findSandbox()).toBeHidden();
});

it("should pass on hidden element", function() {
var node=sandbox();
node.style.visibility='hidden';
setFixtures(node);
expect(findSandbox()).toBeHidden();
});

it("should pass negated on visible element", function() {
setFixtures(sandbox());
expect(findSandbox()).not.toBeHidden();
Expand Down Expand Up @@ -562,4 +579,4 @@ describe("DOM matchers", function() {
expect(findSandbox()).not.toContain('div');
});
});
});
});

0 comments on commit 4ab5ff8

Please sign in to comment.