Comparing version 1.9.0 to 1.10.0
@@ -389,2 +389,17 @@ (function(chaiDom) { | ||
}) | ||
chai.Assertion.overwriteProperty('focus', function() { | ||
return function () { | ||
var el = flag(this, 'object'), actual = el.ownerDocument.activeElement | ||
this.assert( | ||
el === el.ownerDocument.activeElement | ||
, 'expected #{this} to have focus' | ||
, 'expected #{this} not to have focus' | ||
, el | ||
, actual | ||
) | ||
} | ||
}) | ||
})); |
@@ -16,3 +16,3 @@ { | ||
], | ||
"version": "1.9.0", | ||
"version": "1.10.0", | ||
"license": "MIT", | ||
@@ -19,0 +19,0 @@ "repository": { |
@@ -187,2 +187,11 @@ # chai-dom | ||
### `focus` | ||
Assert that the [HTMLElement][] has set focus. | ||
```js | ||
document.querySelector('input').should.have.focus | ||
expect(document.querySelector('.container')).not.to.have.focus | ||
``` | ||
## Installation | ||
@@ -189,0 +198,0 @@ |
@@ -1001,2 +1001,39 @@ describe('DOM assertions', function() { | ||
}) | ||
describe('focus', function() { | ||
var container = document.getElementById("mocha"); | ||
var focused = parse('<input type="text" id="focused" name="focused">'); | ||
var blurred = parse('<input type="text" id="blurred" name="blurred">'); | ||
beforeEach(function() { | ||
container.appendChild(focused) | ||
container.appendChild(blurred) | ||
focused.focus(); | ||
}); | ||
afterEach(function() { | ||
container.removeChild(focused) | ||
container.removeChild(blurred) | ||
}); | ||
it("passes when the element has focus", function(){ | ||
focused.should.have.focus; | ||
}); | ||
it("passes negated when the element does not have focus", function(){ | ||
blurred.should.not.have.focus; | ||
}); | ||
it("fails when the element does not have focus", function(){ | ||
(function(){ | ||
blurred.should.have.focus; | ||
}).should.fail("expected " + inspect(blurred) + " to have focus"); | ||
}); | ||
it("fails negated when element has focus", function(){ | ||
(function(){ | ||
focused.should.not.have.focus; | ||
}).should.fail("expected " + inspect(focused) + " not to have focus"); | ||
}); | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
62987
1261
252