Skip to content

Commit

Permalink
refactor: CSS Style Declaration types to support latest TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryThePenguin committed Jul 31, 2020
1 parent cef4a43 commit a7e6011
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 @@ -730,14 +730,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 @@ -747,7 +747,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 @@ -800,15 +800,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 @@ -818,7 +818,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 a7e6011

Please sign in to comment.