Skip to content

Commit

Permalink
Merge pull request #773 from BarryThePenguin/refactor/css-declaration…
Browse files Browse the repository at this point in the history
…-types

Refactor CSS Style Declaration types to support latest TypeScript
  • Loading branch information
Turbo87 authored Aug 1, 2020
2 parents 0b8a272 + a7e6011 commit a4eb05e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export interface ExistsOptions {
count: number;
}

export interface Dictionary<T> {
[key: string]: T;
}
type CSSStyleDeclarationProperty = keyof CSSStyleDeclaration;

type ActualCSSStyleDeclaration = Partial<Record<CSSStyleDeclarationProperty, unknown>>;

export default class DOMAssertions {
constructor(
Expand Down Expand Up @@ -749,14 +749,14 @@ export default class DOMAssertions {
*/
hasPseudoElementStyle(
selector: string | null,
expected: Dictionary<string>,
expected: Record<string, string>,
message?: string
): DOMAssertions {
let element = this.findTargetElement();
if (!element) return this;

let computedStyle = window.getComputedStyle(element, selector);
let expectedProperties = Object.keys(expected) as [keyof CSSStyleDeclaration];
let expectedProperties = Object.keys(expected) as CSSStyleDeclarationProperty[];
if (expectedProperties.length <= 0) {
throw new TypeError(
`Missing style expectations. There must be at least one style property in the passed in expectation object.`
Expand All @@ -766,7 +766,7 @@ export default class DOMAssertions {
let result = expectedProperties.every(
property => computedStyle[property] === expected[property]
);
let actual: Dictionary<string> = {};
let actual: ActualCSSStyleDeclaration = {};

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

Expand Down Expand Up @@ -819,15 +819,15 @@ export default class DOMAssertions {
*/
doesNotHavePseudoElementStyle(
selector: string | null,
expected: Dictionary<any>,
expected: Record<string, unknown>,
message: string
): DOMAssertions {
let element = this.findTargetElement();
if (!element) return this;

let computedStyle = window.getComputedStyle(element, selector);

let expectedProperties = Object.keys(expected) as [keyof CSSStyleDeclaration];
let expectedProperties = Object.keys(expected) as CSSStyleDeclarationProperty[];
if (expectedProperties.length <= 0) {
throw new TypeError(
`Missing style expectations. There must be at least one style property in the passed in expectation object.`
Expand All @@ -837,7 +837,7 @@ export default class DOMAssertions {
let result = expectedProperties.some(
property => computedStyle[property] !== expected[property]
);
let actual: Dictionary<any> = {};
let actual: ActualCSSStyleDeclaration = {};

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

Expand Down

0 comments on commit a4eb05e

Please sign in to comment.