test-drive
Advanced tools
Comparing version 1.1.3 to 1.1.4
@@ -5,3 +5,3 @@ "use strict"; | ||
function isPresent(element) { | ||
return (helpers_1.isElement(element) && | ||
return ((0, helpers_1.isElement)(element) && | ||
[...element.getClientRects()].some((rectangle) => rectangle.width > 0 && rectangle.height > 0)); | ||
@@ -8,0 +8,0 @@ } |
/// <reference types="chai" /> | ||
export declare function getBoundaries(element: Element): ClientRect; | ||
export declare function getBoundaries(element: Element): DOMRect; | ||
export declare function detectMisalignment(edges: number[], tolerance?: number): number[]; | ||
export default function use(chai: Chai.ChaiStatic, util: Chai.ChaiUtils): void; | ||
//# sourceMappingURL=layout.d.ts.map |
@@ -49,4 +49,4 @@ "use strict"; | ||
function getEdgeAccessors(direction) { | ||
const edgeProps = propsByDirection[direction]; | ||
return [(rect) => rect[edgeProps[0]], (rect) => rect[edgeProps[1]]]; | ||
const [prop1, prop2] = propsByDirection[direction]; | ||
return [(rect) => rect[prop1], (rect) => rect[prop2]]; | ||
} | ||
@@ -95,3 +95,2 @@ function findLastElementOfSequence(elements, direction, tolerance = 1, distance = 0) { | ||
} | ||
const property = alignment; | ||
const edges = alignment === 'center' | ||
@@ -107,3 +106,3 @@ ? elementList.map((element) => { | ||
}) | ||
: elementList.map((element) => getBoundaries(element)[property]); | ||
: elementList.map((element) => getBoundaries(element)[alignment]); | ||
const misaligned = detectMisalignment(edges, tolerance); | ||
@@ -152,3 +151,3 @@ this.assert(misaligned.length === 0, `Expected elements to be ${direction}ly aligned to "${alignment}" but some weren't. ([${misaligned.join(', ')}])`, `Expected elements not to be ${direction}ly aligned to "${alignment}" but they were.`, 0, misaligned.length); | ||
const layout = util.flag(this, 'layout'); | ||
if (layout && helpers_1.isElement(x)) { | ||
if (layout && (0, helpers_1.isElement)(x)) { | ||
_super.call(this, getBoundaries(x)[layout]); | ||
@@ -155,0 +154,0 @@ } |
@@ -13,3 +13,3 @@ "use strict"; | ||
const elementList = [...parentElement.querySelectorAll(selectorExpr)]; | ||
if (dom_matches_1.default(parentElement, selectorExpr)) { | ||
if ((0, dom_matches_1.default)(parentElement, selectorExpr)) { | ||
elementList.unshift(parentElement); | ||
@@ -16,0 +16,0 @@ } |
/// <reference types="chai" /> | ||
export declare function getBoundaries(element: Element): ClientRect; | ||
export declare function getBoundaries(element: Element): DOMRect; | ||
export declare function detectMisalignment(edges: number[], tolerance?: number): number[]; | ||
export default function use(chai: Chai.ChaiStatic, util: Chai.ChaiUtils): void; | ||
//# sourceMappingURL=layout.d.ts.map |
@@ -44,4 +44,4 @@ import { isElement } from './helpers'; | ||
function getEdgeAccessors(direction) { | ||
const edgeProps = propsByDirection[direction]; | ||
return [(rect) => rect[edgeProps[0]], (rect) => rect[edgeProps[1]]]; | ||
const [prop1, prop2] = propsByDirection[direction]; | ||
return [(rect) => rect[prop1], (rect) => rect[prop2]]; | ||
} | ||
@@ -90,3 +90,2 @@ function findLastElementOfSequence(elements, direction, tolerance = 1, distance = 0) { | ||
} | ||
const property = alignment; | ||
const edges = alignment === 'center' | ||
@@ -102,3 +101,3 @@ ? elementList.map((element) => { | ||
}) | ||
: elementList.map((element) => getBoundaries(element)[property]); | ||
: elementList.map((element) => getBoundaries(element)[alignment]); | ||
const misaligned = detectMisalignment(edges, tolerance); | ||
@@ -105,0 +104,0 @@ this.assert(misaligned.length === 0, `Expected elements to be ${direction}ly aligned to "${alignment}" but some weren't. ([${misaligned.join(', ')}])`, `Expected elements not to be ${direction}ly aligned to "${alignment}" but they were.`, 0, misaligned.length); |
{ | ||
"name": "test-drive", | ||
"version": "1.1.3", | ||
"version": "1.1.4", | ||
"description": "Opinionated library for writing web component tests", | ||
@@ -16,3 +16,3 @@ "main": "./cjs/index.js", | ||
"test": "mocha-play \"./test/**/*.spec.ts\"", | ||
"lint": "eslint . -f codeframe", | ||
"lint": "eslint .", | ||
"typecheck": "tsc --noEmit" | ||
@@ -23,32 +23,31 @@ }, | ||
"chai-as-promised": "^7.1.1", | ||
"chai-dom": "^1.9.0", | ||
"chai-dom": "^1.10.0", | ||
"chai-style": "^1.0.3", | ||
"dom-matches": "^2.0.0", | ||
"promise-assist": "^1.3.0", | ||
"sinon": "^11.1.1", | ||
"sinon": "^12.0.1", | ||
"sinon-chai": "^3.7.0" | ||
}, | ||
"devDependencies": { | ||
"@ts-tools/webpack-loader": "^2.1.1", | ||
"@types/chai": "^4.2.18", | ||
"@ts-tools/webpack-loader": "^3.0.2", | ||
"@types/chai": "^4.2.22", | ||
"@types/chai-as-promised": "^7.1.4", | ||
"@types/chai-dom": "^0.0.10", | ||
"@types/chai-dom": "^0.0.11", | ||
"@types/chai-style": "^1.0.0", | ||
"@types/dom-matches": "^2.0.0", | ||
"@types/mocha": "^8.2.2", | ||
"@types/sinon": "^10.0.1", | ||
"@types/mocha": "^9.0.0", | ||
"@types/sinon": "^10.0.6", | ||
"@types/sinon-chai": "^3.2.5", | ||
"@typescript-eslint/eslint-plugin": "^4.25.0", | ||
"@typescript-eslint/parser": "^4.25.0", | ||
"eslint": "^7.27.0", | ||
"@typescript-eslint/eslint-plugin": "^5.3.0", | ||
"@typescript-eslint/parser": "^5.3.0", | ||
"eslint": "^8.1.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-no-only-tests": "^2.6.0", | ||
"html-webpack-plugin": "^5.3.1", | ||
"mocha": "^8.4.0", | ||
"mocha-play": "^1.0.1", | ||
"playwright-chromium": "^1.11.1", | ||
"mocha": "^9.1.3", | ||
"mocha-play": "^3.0.0", | ||
"playwright-chromium": "^1.16.3", | ||
"rimraf": "^3.0.2", | ||
"typescript": "~4.3.2", | ||
"util": "^0.12.3", | ||
"webpack": "^5.38.1" | ||
"typescript": "~4.4.4", | ||
"util": "^0.12.4", | ||
"webpack": "^5.61.0" | ||
}, | ||
@@ -55,0 +54,0 @@ "files": [ |
@@ -13,11 +13,11 @@ import { isElement } from './helpers'; | ||
export function getBoundaries(element: Element): ClientRect { | ||
export function getBoundaries(element: Element): DOMRect { | ||
return element.getBoundingClientRect(); | ||
} | ||
function isPointInside(pt: Point, boundaries: ClientRect): boolean { | ||
function isPointInside(pt: Point, boundaries: DOMRect): boolean { | ||
return pt.x >= boundaries.left && pt.x <= boundaries.right && pt.y >= boundaries.top && pt.y <= boundaries.bottom; | ||
} | ||
function isInside(rect: ClientRect, boundaries: ClientRect): boolean { | ||
function isInside(rect: DOMRect, boundaries: DOMRect): boolean { | ||
return ( | ||
@@ -31,3 +31,3 @@ rect.left >= boundaries.left && | ||
function isOutside(rect: ClientRect, boundaries: ClientRect): boolean { | ||
function isOutside(rect: DOMRect, boundaries: DOMRect): boolean { | ||
return !( | ||
@@ -80,14 +80,13 @@ isPointInside({ x: rect.left, y: rect.top }, boundaries) || | ||
} | ||
type BoxProps = keyof ClientRect; | ||
const propsByDirection: { [direction: string]: [BoxProps, BoxProps] } = { | ||
horizontal: ['right', 'left'], | ||
vertical: ['bottom', 'top'], | ||
const propsByDirection = { | ||
horizontal: ['right', 'left'] as const, | ||
vertical: ['bottom', 'top'] as const, | ||
}; | ||
type EdgeAccessor = (rect: ClientRect) => number; | ||
type EdgeAccessor = (rect: DOMRect) => number; | ||
function getEdgeAccessors(direction: Direction): [EdgeAccessor, EdgeAccessor] { | ||
const edgeProps = propsByDirection[direction]; | ||
return [(rect: ClientRect) => rect[edgeProps[0]], (rect) => rect[edgeProps[1]]]; | ||
const [prop1, prop2] = propsByDirection[direction]; | ||
return [(rect) => rect[prop1], (rect) => rect[prop2]]; | ||
} | ||
@@ -178,3 +177,2 @@ | ||
const property: BoxProps = alignment as BoxProps; | ||
const edges: number[] = | ||
@@ -190,3 +188,3 @@ alignment === 'center' | ||
}) | ||
: elementList.map((element) => getBoundaries(element)[property]); | ||
: elementList.map((element) => getBoundaries(element)[alignment]); | ||
const misaligned = detectMisalignment(edges, tolerance); | ||
@@ -205,12 +203,11 @@ this.assert( | ||
chai.Assertion.addMethod('verticallyAligned', function (alignment: VerticalAlignment, tolerance = 0) { | ||
assertAlignment.call(this, 'vertical', alignment, tolerance); | ||
assertAlignment.call(this, 'vertical', alignment, tolerance as number); | ||
}); | ||
chai.Assertion.addMethod('horizontallyAligned', function ( | ||
this: Chai.AssertionStatic, | ||
alignment: HorizontalAlignment, | ||
tolerance = 0 | ||
) { | ||
assertAlignment.call(this, 'horizontal', alignment, tolerance); | ||
}); | ||
chai.Assertion.addMethod( | ||
'horizontallyAligned', | ||
function (this: Chai.AssertionStatic, alignment: HorizontalAlignment, tolerance = 0) { | ||
assertAlignment.call(this, 'horizontal', alignment, tolerance as number); | ||
} | ||
); | ||
@@ -267,3 +264,3 @@ function assertSequence( | ||
return function (this: Chai.AssertionStatic, x: number | Element) { | ||
const layout: BoxProps = util.flag(this, 'layout') as BoxProps; | ||
const layout = util.flag(this, 'layout') as Exclude<keyof DOMRect, 'toJSON'>; | ||
if (layout && isElement(x)) { | ||
@@ -270,0 +267,0 @@ _super.call(this, getBoundaries(x)[layout]); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
21
94379
1164
+ Added@sinonjs/fake-timers@8.1.0(transitive)
+ Addedsinon@12.0.1(transitive)
- Removed@sinonjs/fake-timers@7.1.2(transitive)
- Removedsinon@11.1.2(transitive)
Updatedchai-dom@^1.10.0
Updatedsinon@^12.0.1