Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chai-dom

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-dom - npm Package Compare versions

Comparing version 1.4.3 to 1.5.0

32

chai-dom.js

@@ -16,3 +16,3 @@ (function(chaiDom) {

var desc
if (el instanceof NodeList) {
if (el instanceof window.NodeList) {
if (el.length === 0) return 'empty NodeList'

@@ -22,3 +22,3 @@ desc = Array.prototype.slice.call(el, 0, 5).map(elToString).join(', ')

}
if (!(el instanceof HTMLElement)) {
if (!(el instanceof window.HTMLElement)) {
return String(el)

@@ -116,3 +116,3 @@ }

if (obj instanceof NodeList) {
if (obj instanceof window.NodeList) {
actual = Array.prototype.map.call(obj, function(el) { return el.textContent })

@@ -172,3 +172,3 @@ if (Array.isArray(text)) {

var obj = flag(this, 'object')
if (obj instanceof NodeList) {
if (obj instanceof window.NodeList) {
this.assert(

@@ -187,3 +187,3 @@ obj.length > 0

var obj = flag(this, 'object')
if (obj instanceof HTMLElement) {
if (obj instanceof window.HTMLElement) {
this.assert(

@@ -193,3 +193,3 @@ obj.children.length === 0

, 'expected ' + elToString(obj) + ' to not be empty')
} else if (obj instanceof NodeList) {
} else if (obj instanceof window.NodeList) {
this.assert(

@@ -209,3 +209,3 @@ obj.length === 0

var obj = flag(this, 'object')
if (obj instanceof NodeList || obj instanceof HTMLElement) {
if (obj instanceof window.NodeList || obj instanceof window.HTMLElement) {
var actualLength = obj.children ? obj.children.length : obj.length;

@@ -235,3 +235,3 @@ this.assert(

var obj = flag(this, 'object')
if (obj instanceof HTMLElement) {
if (obj instanceof window.HTMLElement) {
this.assert(

@@ -243,3 +243,3 @@ obj.matches(selector)

)
} else if (obj instanceof NodeList) {
} else if (obj instanceof window.NodeList) {
this.assert(

@@ -261,3 +261,3 @@ (!!obj.length && Array.prototype.every.call(obj, function(el) { return el.matches(selector) }))

var obj = flag(this, 'object')
if (obj instanceof HTMLElement) {
if (obj instanceof window.HTMLElement) {
if (typeof subitem === 'string') {

@@ -286,2 +286,14 @@ this.assert(

)
chai.Assertion.addProperty('displayed', function() {
var el = flag(this, 'object'),
actual = document.body.contains(el) ? window.getComputedStyle(el).display : el.style.display
this.assert(
actual !== 'none'
, 'expected ' + elToString(el) + ' to be displayed, but it was not'
, 'expected ' + elToString(el) + ' to not be displayed, but it was as ' + actual
, actual
)
})
}));

@@ -16,3 +16,3 @@ {

],
"version": "1.4.3",
"version": "1.5.0",
"repository": {

@@ -19,0 +19,0 @@ "type": "git",

@@ -89,3 +89,3 @@ # chai-dom

### `empty`
Assert that at the [HTMLElement][] or [NodeList][] has no child nodes. If the object asserted against is niether of those, the original implementation will be called.
Assert that the [HTMLElement][] or [NodeList][] has no child nodes. If the object asserted against is neither of those, the original implementation will be called.

@@ -98,3 +98,3 @@ ```js

### `length(n)`
Assert that at the [HTMLElement][] or [NodeList][] has exactly `n` child nodes. If the object asserted against is niether of those, the original implementation will be called.
Assert that the [HTMLElement][] or [NodeList][] has exactly `n` child nodes. If the object asserted against is neither of those, the original implementation will be called.

@@ -136,2 +136,10 @@ ```js

### `displayed`
Assert that the [HTMLElement][] is displayed (that display is not equal to "none"). If the element is attached to the body, it will call [`getComputedStyle`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle); otherwise it will look at the inline display attribute.
```js
document.querySelector('dl dd').should.be.displayed
expect(document.querySelector('.hidden')).not.to.be.displayed
```
## Installation

@@ -188,2 +196,2 @@

[HTMLElement]: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
[NodeList]: https://developer.mozilla.org/en-US/docs/Web/API/NodeList
[NodeList]: https://developer.mozilla.org/en-US/docs/Web/API/NodeList

@@ -603,5 +603,60 @@ describe('DOM assertions', function() {

})
it('should not change the assertion subject', function() {
subject.should.contain('.blurb').and.contain('p')
})
})
})
describe('displayed', function() {
var div = document.createElement('div'),
notDisplayedViaStyle = parse('<div style="display: none"></div>'),
notDisplayedViaCSS = parse('<div class="hidden"></div>'),
inlineDiv = parse('<div style="display: inline-block"></div>')
before(function() {
document.styleSheets[0].insertRule('.hidden { display: none; }', 1);
document.body.appendChild(notDisplayedViaCSS)
document.body.appendChild(div)
})
after(function() {
document.body.removeChild(notDisplayedViaCSS)
document.body.removeChild(div)
})
it('passes when displayed (any display value but none)', function() {
div.should.be.displayed
inlineDiv.should.be.displayed
})
it('passes negated when the elment has display set to "none"', function() {
notDisplayedViaStyle.should.not.be.displayed
notDisplayedViaCSS.should.not.be.displayed
})
it('fails when the element has display: none', function() {
(function() {
notDisplayedViaStyle.should.be.displayed
}).should.fail('expected div[style="display: none"] to be displayed, but it was not')
;(function() {
notDisplayedViaCSS.should.be.displayed
}).should.fail('expected div.hidden to be displayed, but it was not')
})
it('fails negated when the element is displayed', function() {
(function() {
div.should.not.be.displayed
}).should.fail('expected div to not be displayed, but it was as block')
;(function() {
inlineDiv.should.not.be.displayed
}).should.fail('expected div[style="display: inline-block"] to not be displayed, but it was as inline-block')
})
it('should be chainable', function() {
div.should.be.displayed.and.exist.and.be.ok
})
})
describe('util.elToString', function() {

@@ -608,0 +663,0 @@ it('should give a friendly name for a HTMLElement', function() {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc