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.10.0 to 1.11.0

27

chai-dom.js

@@ -82,2 +82,12 @@ (function(chaiDom) {

var el = flag(this, 'object')
if (className instanceof RegExp) {
return this.assert(
Array.from(el.classList).some(function(cls) { return className.test(cls) })
, 'expected ' + elToString(el) + ' to have class matching #{exp}'
, 'expected ' + elToString(el) + ' not to have class matching #{exp}'
, className
)
}
this.assert(

@@ -381,3 +391,3 @@ el.classList.contains(className)

style = window.getComputedStyle(el),
actual = style[styleProp];
actual = style.getPropertyValue(styleProp).trim();

@@ -406,2 +416,17 @@ this.assert(

})
chai.Assertion.overwriteProperty('checked', function() {
return function () {
var el = flag(this, 'object')
if(!(el instanceof HTMLInputElement && (el.type === 'checkbox' || el.type === 'radio'))) {
throw new TypeError(elToString(el) + ' is not a checkbox or radio input');
}
this.assert(
el.checked
, 'expected ' + elToString(el) + ' to be checked'
, 'expected ' + elToString(el) + ' to not be checked')
}
})
}));

2

package.json

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

],
"version": "1.10.0",
"version": "1.11.0",
"license": "MIT",

@@ -19,0 +19,0 @@ "repository": {

@@ -32,2 +32,9 @@ # chai-dom

Also accepts regex as argument.
```js
document.getElementsByName('bar').should.have.class(/foo/)
expect(document.querySelector('main article')).to.have.class(/foo/)
```
### `id(id)`

@@ -197,2 +204,11 @@ Assert that the [HTMLElement][] has the given id.

### `checked`
Assert that the [HTMLElement][] is an [HTMLInputElement][] with `type` of "checkbox" or "radio", and that its `checked` state is true or false.
```js
document.querySelector('input').should.be.checked
expect(document.querySelector('.checkbox')).not.to.be.checked
```
## Installation

@@ -199,0 +215,0 @@

@@ -135,2 +135,6 @@ describe('DOM assertions', function() {

it('passes when the element has the class matching given regex', function () {
subject.should.have.class(/foo/)
})
it('passes negated when the element does not have the class', function() {

@@ -140,2 +144,6 @@ subject.should.not.have.class('bar')

it('passes negated when the element does not have the class matching given regex', function () {
subject.should.not.have.class(/bar/)
})
it('fails when the element does not have the class', function() {

@@ -147,2 +155,8 @@ (function() {

it('fails when the element does not have the class matching given regex', function() {
(function() {
subject.should.have.class(/bar/)
}).should.fail('expected div.foo.shazam.baz to have class matching /bar/')
})
it('fails negated when the element has the class', function() {

@@ -153,2 +167,8 @@ (function() {

})
it('fails negated when the element has the class matching given regex', function() {
(function() {
subject.should.not.have.class(/foo/)
}).should.fail('expected div.foo.shazam.baz not to have class matching /foo/')
})
})

@@ -1042,2 +1062,51 @@

})
describe('checked', function() {
var span = parse('<span>Test</span>')
, input = parse('<input>')
, checkedCheckbox = parse('<input type="checkbox" checked>')
, uncheckedCheckbox = parse('<input type="checkbox">')
, checkedRadio = parse('<input type="radio" checked>')
, uncheckedRadio = parse('<input type="radio">')
it('throws when the element is not an radio or checkbox', function() {
(function() {
span.should.be.checked
}).should.throw('span is not a checkbox or radio input')
;(function() {
input.should.be.checked
}).should.throw('input is not a checkbox or radio input')
})
it('passes when checked, positive assertion', function() {
checkedCheckbox.should.be.checked
checkedRadio.should.be.checked
})
it('passes when not checked, negative assertion', function() {
uncheckedCheckbox.should.not.be.checked
uncheckedRadio.should.not.be.checked
})
it('fails when checked, negative assertion', function() {
(function() {
checkedCheckbox.should.not.be.checked
}).should.throw('expected input[type="checkbox"][checked] to not be checked')
;(function() {
checkedRadio.should.not.be.checked
}).should.throw('expected input[type="radio"][checked] to not be checked')
})
it('fails when unchecked, positive assertion', function() {
(function() {
uncheckedCheckbox.should.be.checked
}).should.throw('expected input[type="checkbox"] to be checked')
;(function() {
uncheckedRadio.should.be.checked
}).should.throw('expected input[type="radio"] to be checked')
})
})
})
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