Skip to content

Commit

Permalink
Add tests for styles applied via CSS
Browse files Browse the repository at this point in the history
Co-Authored-By: selvagsz <selvaganeshbsg@gmail.com>
  • Loading branch information
jayjayjpg and selvagsz committed Nov 22, 2018
1 parent 10de58d commit b25a111
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
19 changes: 19 additions & 0 deletions lib/__tests__/has-style.ts
Expand Up @@ -24,6 +24,25 @@ describe('assert.dom(...).hasStyle()', () => {
}]);
});

test('succeeds for checking styles applied by CSS stylesheets', () => {
var styleNode = document.createElement('style');
styleNode.innerHTML = '.foo { color: blue }';
document.body.appendChild(styleNode);
assert.dom('.foo').hasStyle({
opacity: '1',
width: '200px',
'text-align': 'center',
color: 'blue',
});
expect(assert.results).toEqual([{
actual: { opacity: '1', width: '200px', 'text-align': 'center', color: 'blue' },
expected: { opacity: '1', width: '200px', 'text-align': 'center', color: 'blue' },
message: 'Element .foo has style \"{\"opacity\":\"1\",\"width\":\"200px\",\"text-align\":\"center\",\"color\":\"blue\"}\"',
result: true,
}]);
document.body.removeChild(styleNode);
});

test('succeeds for partial style checking', () => {
assert.dom('.foo').hasStyle({
opacity: '1',
Expand Down
6 changes: 0 additions & 6 deletions lib/assertions.ts
Expand Up @@ -454,12 +454,6 @@ export default class DOMAssertions {
let result = expectedProperties.every(property => computedStyle[property] === expected[property]);
let actual = {};
expectedProperties.forEach(property => actual[property] = computedStyle[property]);
for (let property in expected) {
actual[property] = computedStyle[property];
if (!result) {
result = '' + expected[property] === actual[property];
}
}
if (!message) {
message = `Element ${this.targetDescription} has style "${JSON.stringify(expected)}"`;
}
Expand Down

0 comments on commit b25a111

Please sign in to comment.