Skip to content

Commit

Permalink
fix(hasStyle): allow using camelCase properties inside assertion object
Browse files Browse the repository at this point in the history
  • Loading branch information
BobrImperator committed Apr 23, 2024
1 parent 056dd10 commit 7b5892c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
16 changes: 16 additions & 0 deletions packages/qunit-dom/lib/__tests__/has-style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,20 @@ describe('assert.dom(...).hasStyle()', () => {

expect(assert.results.length).toEqual(2);
});

test('succeeds for checking styles using camelCase property as argument', () => {
assert.dom('.foo').hasStyle({
opacity: '1',
width: '200px',
textAlign: 'center',
});
expect(assert.results).toEqual([
{
actual: { opacity: '1', width: '200px', textAlign: 'center' },
expected: { opacity: '1', width: '200px', textAlign: 'center' },
message: 'Element .foo has style "{"opacity":"1","width":"200px","textAlign":"center"}"',
result: true,
},
]);
});
});
8 changes: 6 additions & 2 deletions packages/qunit-dom/lib/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -774,12 +774,16 @@ export default class DOMAssertions {
}

let result = expectedProperties.every(
property => computedStyle.getPropertyValue(property.toString()) === expected[property]
property =>
(computedStyle.getPropertyValue(property.toString()) || computedStyle[property]) ===
expected[property]
);
let actual: ActualCSSStyleDeclaration = {};

expectedProperties.forEach(
property => (actual[property] = computedStyle.getPropertyValue(property.toString()))
property =>
(actual[property] =
computedStyle.getPropertyValue(property.toString()) || computedStyle[property])
);

if (!message) {
Expand Down

0 comments on commit 7b5892c

Please sign in to comment.