chai-style
CSS Style assertions for elements, using Chai.js. All assertions is builtin using window.getComputedStyle
method.
Install
npm install --save-dev chai-style
// in your spec, set the plugin in chaiconst expect =
Style as chainable assertion
Use method .style
to inspect style of a element, e.g.
const element = documenttohavestyle'color' 'red'
Properties can be defined in camel case or separated by hifen, like in css
tohavestyle'backgroundColor'// ortohavestyle'background-color'
Values
To assert a value just pass a second argument to method style, like below
// assert if element has property display with value blacktohavestyle'display' 'block'
Colors
Some browsers can generate a differente value to color, like 'red' or 'rgb(255, 0, 0)'. Whatever, this assertion supports named colors, rgb, rgba, hexadecimal, and hsl
elementstylecolor = '#f00'tohavestyle'color' 'red' // asserts colors indiferrent of value used
Units
To assert unit values, use like css
elementstyleheight = '50vh'tohavestyle'height' '50vh'// too works if you assert with respective value in pixelstohavestyle'height' '323px' // 323 is the half of viewport in this case, equals to 50vh
Actually, the css units supported is
- px (pixels)
- em (relative to element fontStyle, or inherit)
- rem (relative to root fontStyle, the html tag)
- vh (viewport height)
- vw (viewport width)
Other units will come soon. Pull requests be welcome!