New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

test-drive

Package Overview
Dependencies
Maintainers
3
Versions
190
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

test-drive - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

6

cjs/helpers.d.ts

@@ -5,6 +5,6 @@ export interface GenericInputElement {

}
export declare function getGlobalsOf(element: Element): any;
export declare function getGlobalsOf(element: Element): Window & typeof globalThis;
export declare function isInputElement(element: Element): element is Element & GenericInputElement;
export declare function isElement(obj: any): obj is Element;
export declare function isHTMLElement(obj: any): obj is HTMLElement;
export declare function isElement(obj: unknown): obj is Element;
export declare function isHTMLElement(obj: unknown): obj is HTMLElement;
//# sourceMappingURL=helpers.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isHTMLElement = exports.isElement = exports.isInputElement = exports.getGlobalsOf = void 0;
function getGlobalsOf(element) {
if (element.ownerDocument && element.ownerDocument.defaultView) {
return element.ownerDocument.defaultView;
}
else {
return window;
}
var _a, _b;
return (_b = (_a = element.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) !== null && _b !== void 0 ? _b : window;
}

@@ -17,15 +14,15 @@ exports.getGlobalsOf = getGlobalsOf;

const HTMLSelectElement = globalScope['HTMLSelectElement'];
return element instanceof HTMLInputElement ||
return (element instanceof HTMLInputElement ||
element instanceof HTMLTextAreaElement ||
element instanceof HTMLSelectElement;
element instanceof HTMLSelectElement);
}
exports.isInputElement = isInputElement;
function isElement(obj) {
return obj && (obj instanceof getGlobalsOf(obj)['Element']);
return !!obj && obj instanceof getGlobalsOf(obj)['Element'];
}
exports.isElement = isElement;
function isHTMLElement(obj) {
return obj && (obj instanceof getGlobalsOf(obj)['HTMLElement']);
return !!obj && obj instanceof getGlobalsOf(obj)['HTMLElement'];
}
exports.isHTMLElement = isHTMLElement;
//# sourceMappingURL=helpers.js.map
"use strict";
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../matchers.d.ts" />
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -10,2 +18,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
exports.layout = exports.expect = exports.sinon = exports.chai = void 0;
const sinon_1 = __importDefault(require("sinon"));

@@ -22,3 +31,3 @@ exports.sinon = sinon_1.default;

exports.layout = layout_1.default;
__export(require("promise-assist"));
__exportStar(require("promise-assist"), exports);
chai_1.default.use(layout_1.default);

@@ -28,3 +37,4 @@ chai_1.default.use(sinon_chai_1.default);

chai_1.default.use(is_present_1.default);
if (typeof window !== 'undefined') { // chai-dom's matchers are not Node-safe
if (typeof window !== 'undefined') {
// chai-dom's matchers are not Node-safe
chai_1.default.use(chai_dom_1.default);

@@ -35,6 +45,6 @@ chai_1.default.use(chai_style_1.default);

exports.expect = expect;
__export(require("./helpers"));
__export(require("./layout"));
__export(require("./layout-driver"));
__export(require("./select-dom"));
__exportStar(require("./helpers"), exports);
__exportStar(require("./layout"), exports);
__exportStar(require("./layout-driver"), exports);
__exportStar(require("./select-dom"), exports);
//# sourceMappingURL=index.js.map
/// <reference types="chai" />
export default function (chai: Chai.ChaiStatic, util: Chai.ChaiUtils): void;
export default function (chai: Chai.ChaiStatic, { flag }: Chai.ChaiUtils): void;
//# sourceMappingURL=is-present.d.ts.map

@@ -5,20 +5,13 @@ "use strict";

function isPresent(element) {
if (helpers_1.isElement(element)) {
const rects = [...element.getClientRects()];
return rects.some(rectangle => rectangle.width > 0 && rectangle.height > 0);
}
else {
return false;
}
return (helpers_1.isElement(element) &&
[...element.getClientRects()].some((rectangle) => rectangle.width > 0 && rectangle.height > 0));
}
function default_1(chai, util) {
function default_1(chai, { flag }) {
chai.Assertion.addMethod('present', function () {
const { flag } = util;
const element = flag(this, 'object');
this.assert(isPresent(element), 'Element expected to be present.', 'Element expected to be absent.');
this.assert(isPresent(element), 'Element expected to be present.', 'Element expected to be absent.', true);
});
chai.Assertion.addMethod('absent', function () {
const { flag } = util;
const element = flag(this, 'object');
this.assert(!isPresent(element), 'Element expected to be absent.', 'Element expected to be present.');
this.assert(!isPresent(element), 'Element expected to be absent.', 'Element expected to be present.', true);
});

@@ -25,0 +18,0 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLayoutFixture = exports.dom = exports.generateMap = void 0;
function generateMap(source) {

@@ -7,3 +8,3 @@ let col = 0;

const map = {};
for (let ch of source) {
for (const ch of source) {
col++;

@@ -21,3 +22,3 @@ if (ch === '\n') {

const geometry = {};
for (let key in map) {
for (const key in map) {
const record = map[key];

@@ -37,5 +38,5 @@ const x = record[0].col;

const domMap = {
container
container,
};
for (let elementId in layoutMap) {
for (const elementId in layoutMap) {
const element = document.createElement('div');

@@ -45,6 +46,6 @@ const geometry = layoutMap[elementId];

element.style.position = 'absolute';
element.style.left = geometry[0] + 'px';
element.style.top = geometry[1] + 'px';
element.style.width = geometry[2] + 'px';
element.style.height = geometry[3] + 'px';
element.style.left = `${geometry[0]}px`;
element.style.top = `${geometry[1]}px`;
element.style.width = `${geometry[2]}px`;
element.style.height = `${geometry[3]}px`;
container.appendChild(element);

@@ -51,0 +52,0 @@ domMap[elementId] = element;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.detectMisalignment = exports.getBoundaries = void 0;
const helpers_1 = require("./helpers");

@@ -9,10 +10,9 @@ function getBoundaries(element) {

function isPointInside(pt, boundaries) {
return pt.x >= boundaries.left && pt.x <= boundaries.right &&
pt.y >= boundaries.top && pt.y <= boundaries.bottom;
return pt.x >= boundaries.left && pt.x <= boundaries.right && pt.y >= boundaries.top && pt.y <= boundaries.bottom;
}
function isInside(rect, boundaries) {
return rect.left >= boundaries.left &&
return (rect.left >= boundaries.left &&
rect.top >= boundaries.top &&
rect.right <= boundaries.right &&
rect.bottom <= boundaries.bottom;
rect.bottom <= boundaries.bottom);
}

@@ -26,5 +26,3 @@ function isOutside(rect, boundaries) {

function findExcludedEdges(edges, range) {
return edges.reduce((acc, edge, index) => (edge >= range[0] && edge <= range[1])
? acc
: acc.concat(index), []);
return edges.reduce((acc, edge, index) => (edge >= range[0] && edge <= range[1] ? acc : acc.concat(index)), []);
}

@@ -35,3 +33,3 @@ function getEdgeMap(edges, tolerance) {

function pickLeastExcludedEdges(edgeMap) {
const excludedEdgeItem = edgeMap.reduce((acc, item) => (!acc || item.excludedEdges.length < acc.excludedEdges.length) ? item : acc, null);
const excludedEdgeItem = edgeMap.reduce((acc, item) => (!acc || item.excludedEdges.length < acc.excludedEdges.length ? item : acc), null);
if (excludedEdgeItem) {

@@ -50,11 +48,8 @@ return excludedEdgeItem.excludedEdges;

const propsByDirection = {
"horizontal": ['right', 'left'],
"vertical": ['bottom', 'top']
horizontal: ['right', 'left'],
vertical: ['bottom', 'top'],
};
function getEdgeAccessors(direction) {
const edgeProps = propsByDirection[direction];
return [
(rect) => rect[edgeProps[0]],
rect => rect[edgeProps[1]]
];
return [(rect) => rect[edgeProps[0]], (rect) => rect[edgeProps[1]]];
}

@@ -75,15 +70,15 @@ function findLastElementOfSequence(elements, direction, tolerance = 1, distance = 0) {

const element = util.flag(this, 'object');
this.assert(isInside(getBoundaries(element), getBoundaries(boundaryElement)), 'Expected element to be inside of the other, but it wasn\'t.', 'Expected element not to be inside of the other, but it was.');
this.assert(isInside(getBoundaries(element), getBoundaries(boundaryElement)), "Expected element to be inside of the other, but it wasn't.", 'Expected element not to be inside of the other, but it was.', true);
});
chai.Assertion.addMethod('outsideOf', function (boundaryElement) {
const element = util.flag(this, 'object');
this.assert(isOutside(getBoundaries(element), getBoundaries(boundaryElement)), 'Expected element to be outside of the other, but it wasn\'t.', 'Expected element not to be outside of the other, but it was.');
this.assert(isOutside(getBoundaries(element), getBoundaries(boundaryElement)), "Expected element to be outside of the other, but it wasn't.", 'Expected element not to be outside of the other, but it was.', true);
});
chai.Assertion.addMethod('widerThan', function (comparedTo) {
const element = util.flag(this, 'object');
this.assert(getBoundaries(element).width > getBoundaries(comparedTo).width, 'Expected element to be wider than the other, but it wasn\'t.', 'Expected element not to be wider than the other, but it was.');
this.assert(getBoundaries(element).width > getBoundaries(comparedTo).width, "Expected element to be wider than the other, but it wasn't.", 'Expected element not to be wider than the other, but it was.', true);
});
chai.Assertion.addMethod('higherThan', function (comparedTo) {
const element = util.flag(this, 'object');
this.assert(getBoundaries(element).height > getBoundaries(comparedTo).height, 'Expected element to be higher than the other, but it wasn\'t.', 'Expected element not to be higher than the other, but it was.');
this.assert(getBoundaries(element).height > getBoundaries(comparedTo).height, "Expected element to be higher than the other, but it wasn't.", 'Expected element not to be higher than the other, but it was.', true);
});

@@ -94,3 +89,3 @@ chai.Assertion.addMethod('biggerThan', function (comparedTo) {

const comparedRect = getBoundaries(comparedTo);
this.assert((elementRect.width * elementRect.height) > (comparedRect.width * comparedRect.height), 'Expected element to be bigger than the other, but it wasn\'t.', 'Expected element not to be bigger than the other, but it was.');
this.assert(elementRect.width * elementRect.height > comparedRect.width * comparedRect.height, "Expected element to be bigger than the other, but it wasn't.", 'Expected element not to be bigger than the other, but it was.', true);
});

@@ -107,5 +102,5 @@ function assertAlignment(direction, alignment, tolerance) {

const edges = alignment === 'center'
? elementList.map(element => {
? elementList.map((element) => {
const rect = getBoundaries(element);
if (direction === "horizontal") {
if (direction === 'horizontal') {
return (rect.left + rect.right) / 2.0;

@@ -117,11 +112,11 @@ }

})
: elementList.map(element => getBoundaries(element)[property]);
: elementList.map((element) => getBoundaries(element)[property]);
const misaligned = detectMisalignment(edges, tolerance);
this.assert(misaligned.length === 0, `Expected elements to be ${direction}ly aligned to "${alignment}" but some weren\'t. ([${misaligned}])`, `Expected elements not to be ${direction}ly aligned to "${alignment}" but they were.`);
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);
}
chai.Assertion.addMethod('verticallyAligned', function (alignment, tolerance = 0) {
assertAlignment.call(this, "vertical", alignment, tolerance);
assertAlignment.call(this, 'vertical', alignment, tolerance);
});
chai.Assertion.addMethod('horizontallyAligned', function (alignment, tolerance = 0) {
assertAlignment.call(this, "horizontal", alignment, tolerance);
assertAlignment.call(this, 'horizontal', alignment, tolerance);
});

@@ -137,9 +132,9 @@ function assertSequence(direction, tolerance, distanceBetween) {

const lastElementOfSequence = findLastElementOfSequence(elementList, direction, tolerance, distanceBetween);
this.assert(lastElementOfSequence === elementList.length, `Expected elements to form ${direction} sequence, but they didn\'t. (${lastElementOfSequence})`, `Expected elements not to form ${direction} sequence, but they did.`);
this.assert(lastElementOfSequence === elementList.length, `Expected elements to form ${direction} sequence, but they didn't. (${lastElementOfSequence})`, `Expected elements not to form ${direction} sequence, but they did.`, elementList.length, lastElementOfSequence);
}
chai.Assertion.addMethod('inHorizontalSequence', function (options = {}) {
assertSequence.call(this, "horizontal", options.tolerance, options.distance);
assertSequence.call(this, 'horizontal', options.tolerance, options.distance);
});
chai.Assertion.addMethod('inVerticalSequence', function (options = {}) {
assertSequence.call(this, "vertical", options.tolerance, options.distance);
assertSequence.call(this, 'vertical', options.tolerance, options.distance);
});

@@ -172,3 +167,3 @@ chai.Assertion.addProperty('width', function () {

const propList = ['width', 'height', 'top', 'bottom', 'left', 'right'];
propList.forEach(propName => chai.Assertion.addProperty(propName, layoutProperty(propName)));
propList.forEach((propName) => chai.Assertion.addProperty(propName, layoutProperty(propName)));
chai.Assertion.overwriteMethod('greaterThan', compare);

@@ -175,0 +170,0 @@ chai.Assertion.overwriteMethod('lessThan', compare);

@@ -6,2 +6,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.selectDom = void 0;
const dom_matches_1 = __importDefault(require("dom-matches"));

@@ -8,0 +9,0 @@ function selectDom(container, attrName = 'data-automation-id') {

@@ -5,6 +5,6 @@ export interface GenericInputElement {

}
export declare function getGlobalsOf(element: Element): any;
export declare function getGlobalsOf(element: Element): Window & typeof globalThis;
export declare function isInputElement(element: Element): element is Element & GenericInputElement;
export declare function isElement(obj: any): obj is Element;
export declare function isHTMLElement(obj: any): obj is HTMLElement;
export declare function isElement(obj: unknown): obj is Element;
export declare function isHTMLElement(obj: unknown): obj is HTMLElement;
//# sourceMappingURL=helpers.d.ts.map
export function getGlobalsOf(element) {
if (element.ownerDocument && element.ownerDocument.defaultView) {
return element.ownerDocument.defaultView;
}
else {
return window;
}
var _a, _b;
return (_b = (_a = element.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView) !== null && _b !== void 0 ? _b : window;
}

@@ -14,12 +10,12 @@ export function isInputElement(element) {

const HTMLSelectElement = globalScope['HTMLSelectElement'];
return element instanceof HTMLInputElement ||
return (element instanceof HTMLInputElement ||
element instanceof HTMLTextAreaElement ||
element instanceof HTMLSelectElement;
element instanceof HTMLSelectElement);
}
export function isElement(obj) {
return obj && (obj instanceof getGlobalsOf(obj)['Element']);
return !!obj && obj instanceof getGlobalsOf(obj)['Element'];
}
export function isHTMLElement(obj) {
return obj && (obj instanceof getGlobalsOf(obj)['HTMLElement']);
return !!obj && obj instanceof getGlobalsOf(obj)['HTMLElement'];
}
//# sourceMappingURL=helpers.js.map

@@ -0,1 +1,2 @@

// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../matchers.d.ts" />

@@ -15,3 +16,4 @@ import sinon from 'sinon';

chai.use(isPresent);
if (typeof window !== 'undefined') { // chai-dom's matchers are not Node-safe
if (typeof window !== 'undefined') {
// chai-dom's matchers are not Node-safe
chai.use(chaiDom);

@@ -18,0 +20,0 @@ chai.use(chaiStyle);

/// <reference types="chai" />
export default function (chai: Chai.ChaiStatic, util: Chai.ChaiUtils): void;
export default function (chai: Chai.ChaiStatic, { flag }: Chai.ChaiUtils): void;
//# sourceMappingURL=is-present.d.ts.map
import { isElement } from './helpers';
function isPresent(element) {
if (isElement(element)) {
const rects = [...element.getClientRects()];
return rects.some(rectangle => rectangle.width > 0 && rectangle.height > 0);
}
else {
return false;
}
return (isElement(element) &&
[...element.getClientRects()].some((rectangle) => rectangle.width > 0 && rectangle.height > 0));
}
export default function (chai, util) {
export default function (chai, { flag }) {
chai.Assertion.addMethod('present', function () {
const { flag } = util;
const element = flag(this, 'object');
this.assert(isPresent(element), 'Element expected to be present.', 'Element expected to be absent.');
this.assert(isPresent(element), 'Element expected to be present.', 'Element expected to be absent.', true);
});
chai.Assertion.addMethod('absent', function () {
const { flag } = util;
const element = flag(this, 'object');
this.assert(!isPresent(element), 'Element expected to be absent.', 'Element expected to be present.');
this.assert(!isPresent(element), 'Element expected to be absent.', 'Element expected to be present.', true);
});
}
//# sourceMappingURL=is-present.js.map

@@ -5,3 +5,3 @@ export function generateMap(source) {

const map = {};
for (let ch of source) {
for (const ch of source) {
col++;

@@ -19,3 +19,3 @@ if (ch === '\n') {

const geometry = {};
for (let key in map) {
for (const key in map) {
const record = map[key];

@@ -34,5 +34,5 @@ const x = record[0].col;

const domMap = {
container
container,
};
for (let elementId in layoutMap) {
for (const elementId in layoutMap) {
const element = document.createElement('div');

@@ -42,6 +42,6 @@ const geometry = layoutMap[elementId];

element.style.position = 'absolute';
element.style.left = geometry[0] + 'px';
element.style.top = geometry[1] + 'px';
element.style.width = geometry[2] + 'px';
element.style.height = geometry[3] + 'px';
element.style.left = `${geometry[0]}px`;
element.style.top = `${geometry[1]}px`;
element.style.width = `${geometry[2]}px`;
element.style.height = `${geometry[3]}px`;
container.appendChild(element);

@@ -48,0 +48,0 @@ domMap[elementId] = element;

@@ -6,10 +6,9 @@ import { isElement } from './helpers';

function isPointInside(pt, boundaries) {
return pt.x >= boundaries.left && pt.x <= boundaries.right &&
pt.y >= boundaries.top && pt.y <= boundaries.bottom;
return pt.x >= boundaries.left && pt.x <= boundaries.right && pt.y >= boundaries.top && pt.y <= boundaries.bottom;
}
function isInside(rect, boundaries) {
return rect.left >= boundaries.left &&
return (rect.left >= boundaries.left &&
rect.top >= boundaries.top &&
rect.right <= boundaries.right &&
rect.bottom <= boundaries.bottom;
rect.bottom <= boundaries.bottom);
}

@@ -23,5 +22,3 @@ function isOutside(rect, boundaries) {

function findExcludedEdges(edges, range) {
return edges.reduce((acc, edge, index) => (edge >= range[0] && edge <= range[1])
? acc
: acc.concat(index), []);
return edges.reduce((acc, edge, index) => (edge >= range[0] && edge <= range[1] ? acc : acc.concat(index)), []);
}

@@ -32,3 +29,3 @@ function getEdgeMap(edges, tolerance) {

function pickLeastExcludedEdges(edgeMap) {
const excludedEdgeItem = edgeMap.reduce((acc, item) => (!acc || item.excludedEdges.length < acc.excludedEdges.length) ? item : acc, null);
const excludedEdgeItem = edgeMap.reduce((acc, item) => (!acc || item.excludedEdges.length < acc.excludedEdges.length ? item : acc), null);
if (excludedEdgeItem) {

@@ -46,11 +43,8 @@ return excludedEdgeItem.excludedEdges;

const propsByDirection = {
"horizontal": ['right', 'left'],
"vertical": ['bottom', 'top']
horizontal: ['right', 'left'],
vertical: ['bottom', 'top'],
};
function getEdgeAccessors(direction) {
const edgeProps = propsByDirection[direction];
return [
(rect) => rect[edgeProps[0]],
rect => rect[edgeProps[1]]
];
return [(rect) => rect[edgeProps[0]], (rect) => rect[edgeProps[1]]];
}

@@ -71,15 +65,15 @@ function findLastElementOfSequence(elements, direction, tolerance = 1, distance = 0) {

const element = util.flag(this, 'object');
this.assert(isInside(getBoundaries(element), getBoundaries(boundaryElement)), 'Expected element to be inside of the other, but it wasn\'t.', 'Expected element not to be inside of the other, but it was.');
this.assert(isInside(getBoundaries(element), getBoundaries(boundaryElement)), "Expected element to be inside of the other, but it wasn't.", 'Expected element not to be inside of the other, but it was.', true);
});
chai.Assertion.addMethod('outsideOf', function (boundaryElement) {
const element = util.flag(this, 'object');
this.assert(isOutside(getBoundaries(element), getBoundaries(boundaryElement)), 'Expected element to be outside of the other, but it wasn\'t.', 'Expected element not to be outside of the other, but it was.');
this.assert(isOutside(getBoundaries(element), getBoundaries(boundaryElement)), "Expected element to be outside of the other, but it wasn't.", 'Expected element not to be outside of the other, but it was.', true);
});
chai.Assertion.addMethod('widerThan', function (comparedTo) {
const element = util.flag(this, 'object');
this.assert(getBoundaries(element).width > getBoundaries(comparedTo).width, 'Expected element to be wider than the other, but it wasn\'t.', 'Expected element not to be wider than the other, but it was.');
this.assert(getBoundaries(element).width > getBoundaries(comparedTo).width, "Expected element to be wider than the other, but it wasn't.", 'Expected element not to be wider than the other, but it was.', true);
});
chai.Assertion.addMethod('higherThan', function (comparedTo) {
const element = util.flag(this, 'object');
this.assert(getBoundaries(element).height > getBoundaries(comparedTo).height, 'Expected element to be higher than the other, but it wasn\'t.', 'Expected element not to be higher than the other, but it was.');
this.assert(getBoundaries(element).height > getBoundaries(comparedTo).height, "Expected element to be higher than the other, but it wasn't.", 'Expected element not to be higher than the other, but it was.', true);
});

@@ -90,3 +84,3 @@ chai.Assertion.addMethod('biggerThan', function (comparedTo) {

const comparedRect = getBoundaries(comparedTo);
this.assert((elementRect.width * elementRect.height) > (comparedRect.width * comparedRect.height), 'Expected element to be bigger than the other, but it wasn\'t.', 'Expected element not to be bigger than the other, but it was.');
this.assert(elementRect.width * elementRect.height > comparedRect.width * comparedRect.height, "Expected element to be bigger than the other, but it wasn't.", 'Expected element not to be bigger than the other, but it was.', true);
});

@@ -103,5 +97,5 @@ function assertAlignment(direction, alignment, tolerance) {

const edges = alignment === 'center'
? elementList.map(element => {
? elementList.map((element) => {
const rect = getBoundaries(element);
if (direction === "horizontal") {
if (direction === 'horizontal') {
return (rect.left + rect.right) / 2.0;

@@ -113,11 +107,11 @@ }

})
: elementList.map(element => getBoundaries(element)[property]);
: elementList.map((element) => getBoundaries(element)[property]);
const misaligned = detectMisalignment(edges, tolerance);
this.assert(misaligned.length === 0, `Expected elements to be ${direction}ly aligned to "${alignment}" but some weren\'t. ([${misaligned}])`, `Expected elements not to be ${direction}ly aligned to "${alignment}" but they were.`);
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);
}
chai.Assertion.addMethod('verticallyAligned', function (alignment, tolerance = 0) {
assertAlignment.call(this, "vertical", alignment, tolerance);
assertAlignment.call(this, 'vertical', alignment, tolerance);
});
chai.Assertion.addMethod('horizontallyAligned', function (alignment, tolerance = 0) {
assertAlignment.call(this, "horizontal", alignment, tolerance);
assertAlignment.call(this, 'horizontal', alignment, tolerance);
});

@@ -133,9 +127,9 @@ function assertSequence(direction, tolerance, distanceBetween) {

const lastElementOfSequence = findLastElementOfSequence(elementList, direction, tolerance, distanceBetween);
this.assert(lastElementOfSequence === elementList.length, `Expected elements to form ${direction} sequence, but they didn\'t. (${lastElementOfSequence})`, `Expected elements not to form ${direction} sequence, but they did.`);
this.assert(lastElementOfSequence === elementList.length, `Expected elements to form ${direction} sequence, but they didn't. (${lastElementOfSequence})`, `Expected elements not to form ${direction} sequence, but they did.`, elementList.length, lastElementOfSequence);
}
chai.Assertion.addMethod('inHorizontalSequence', function (options = {}) {
assertSequence.call(this, "horizontal", options.tolerance, options.distance);
assertSequence.call(this, 'horizontal', options.tolerance, options.distance);
});
chai.Assertion.addMethod('inVerticalSequence', function (options = {}) {
assertSequence.call(this, "vertical", options.tolerance, options.distance);
assertSequence.call(this, 'vertical', options.tolerance, options.distance);
});

@@ -168,3 +162,3 @@ chai.Assertion.addProperty('width', function () {

const propList = ['width', 'height', 'top', 'bottom', 'left', 'right'];
propList.forEach(propName => chai.Assertion.addProperty(propName, layoutProperty(propName)));
propList.forEach((propName) => chai.Assertion.addProperty(propName, layoutProperty(propName)));
chai.Assertion.overwriteMethod('greaterThan', compare);

@@ -171,0 +165,0 @@ chai.Assertion.overwriteMethod('lessThan', compare);

@@ -9,3 +9,3 @@ type VerticalAlignment = 'top' | 'center' | 'bottom';

declare namespace Chai {
interface Assertion {
export interface Assertion {
present(): Assertion;

@@ -12,0 +12,0 @@ absent(): Assertion;

{
"name": "test-drive",
"version": "1.1.1",
"version": "1.1.2",
"description": "Opinionated library for writing web component tests",

@@ -14,33 +14,40 @@ "main": "./cjs/index.js",

"build:esm": "tsc -p tsconfig.build.json --outDir esm --module esnext",
"typecheck": "tsc --noEmit",
"pretest": "npm run typecheck",
"test": "mocha-pup \"./test/**/*.spec.ts\"",
"prepack": "npm run build"
"pretest": "npm run typecheck && npm run lint",
"test": "mocha-play \"./test/**/*.spec.ts\"",
"lint": "eslint . -f codeframe",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"chai": "^4.2.0",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"chai-dom": "^1.8.1",
"chai-dom": "^1.9.0",
"chai-style": "^1.0.3",
"dom-matches": "^2.0.0",
"promise-assist": "^1.3.0",
"sinon": "^9.0.0",
"sinon-chai": "^3.5.0"
"sinon": "^10.0.0",
"sinon-chai": "^3.6.0"
},
"devDependencies": {
"@ts-tools/webpack-loader": "^1.1.2",
"@types/chai": "^4.2.9",
"@types/chai-as-promised": "^7.1.2",
"@types/chai-dom": "^0.0.8",
"@ts-tools/webpack-loader": "^2.1.1",
"@types/chai": "^4.2.15",
"@types/chai-as-promised": "^7.1.3",
"@types/chai-dom": "^0.0.10",
"@types/chai-style": "^1.0.0",
"@types/dom-matches": "^2.0.0",
"@types/mocha": "^7.0.1",
"@types/sinon": "^7.5.1",
"@types/sinon-chai": "^3.2.3",
"mocha": "^7.0.1",
"mocha-pup": "^2.0.1",
"puppeteer": "^2.1.1",
"@types/mocha": "^8.2.2",
"@types/sinon": "^9.0.11",
"@types/sinon-chai": "^3.2.5",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"eslint": "^7.22.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-no-only-tests": "^2.4.0",
"html-webpack-plugin": "^5.3.1",
"mocha": "^8.3.2",
"mocha-play": "^1.0.1",
"playwright-chromium": "^1.9.2",
"rimraf": "^3.0.2",
"typescript": "~3.7.5",
"webpack": "^4.41.6"
"typescript": "~4.2.3",
"util": "^0.12.3",
"webpack": "^5.27.2"
},

@@ -69,3 +76,20 @@ "files": [

"license": "MIT",
"sideEffects": false
"sideEffects": false,
"prettier": {
"printWidth": 120,
"singleQuote": true,
"tabWidth": 4,
"overrides": [
{
"files": [
"*.json",
"*.md",
"*.yml"
],
"options": {
"tabWidth": 2
}
}
]
}
}
# Test Drive
[![npm version](https://badge.fury.io/js/test-drive.svg)](https://www.npmjs.com/package/test-drive)

@@ -10,6 +11,9 @@ [![Build Status](https://github.com/wixplosives/test-drive/workflows/tests/badge.svg)](https://github.com/wixplosives/test-drive/actions)

test-drive can be installed via the npm registry:
```
npm i test-drive --save-dev
```
If using TypeScript, several @types packages are required as well:
```

@@ -19,3 +23,3 @@ npm i @types/chai @types/sinon @types/sinon-chai @types/chai-dom @types/chai-as-promised --save-dev

**test-drive** exports *sinon* and *chai* via its main entry point. chai's *expect* is also directly exported, and is pre-loaded with chai-as-promised, chai-dom, sinon-chai, and chai-style assertions.
**test-drive** exports _sinon_ and _chai_ via its main entry point. chai's _expect_ is also directly exported, and is pre-loaded with chai-as-promised, chai-dom, sinon-chai, and chai-style assertions.

@@ -34,4 +38,4 @@ ## How to write tests

```tsx
const select = selectDOM(document.body, 'my-id');
const element = select('panel1', 'button-ok');
const select = selectDOM(document.body, 'my-id');
const element = select('panel1', 'button-ok');
```

@@ -59,9 +63,7 @@

```tsx
expect(element).to.be.present();
expect(element).to.be.absent();
expect(element).to.be.present();
expect(element).to.be.absent();
expect(element).not.to.be.present();
expect(element).not.to.be.absent();
expect(element).not.to.be.present();
expect(element).not.to.be.absent();
```

@@ -76,4 +78,3 @@

(This definition is inspired by [jQuery's `:visible` selector]
(https://api.jquery.com/visible-selector/), but not
(This definition is inspired by [jQuery's `:visible` selector](https://api.jquery.com/visible-selector/), but not
necessarily compliant with it.)

@@ -105,3 +106,2 @@

expect(button).to.be.insideOf(panel);
```

@@ -139,3 +139,3 @@

The alignment matchers assert that *all elements within a list* are properly aligned with each other, with optional tolerance range.
The alignment matchers assert that _all elements within a list_ are properly aligned with each other, with optional tolerance range.

@@ -145,3 +145,3 @@ Example:

```javascript
expect([button1, button2, button3]).to.be.verticallyAligned("top", 1.5);
expect([button1, button2, button3]).to.be.verticallyAligned('top', 1.5);
```

@@ -155,3 +155,3 @@

Asserts that *all elements within a list* form uninterrupted sequence, one adjacent to the other, without gaps.
Asserts that _all elements within a list_ form uninterrupted sequence, one adjacent to the other, without gaps.

@@ -175,3 +175,3 @@ Example:

```javascript
expect(button).to.have.style('background-color','green');
expect(button).to.have.style('background-color', 'green');
```

@@ -6,8 +6,4 @@ export interface GenericInputElement {

export function getGlobalsOf(element: Element): any {
if (element.ownerDocument && element.ownerDocument.defaultView) {
return element.ownerDocument.defaultView;
} else {
return window;
}
export function getGlobalsOf(element: Element): Window & typeof globalThis {
return (element.ownerDocument?.defaultView as Window & typeof globalThis) ?? window;
}

@@ -20,13 +16,15 @@

const HTMLSelectElement = globalScope['HTMLSelectElement'];
return element instanceof HTMLInputElement ||
return (
element instanceof HTMLInputElement ||
element instanceof HTMLTextAreaElement ||
element instanceof HTMLSelectElement;
element instanceof HTMLSelectElement
);
}
export function isElement(obj: any): obj is Element {
return obj && (obj instanceof getGlobalsOf(obj)['Element']);
export function isElement(obj: unknown): obj is Element {
return !!obj && obj instanceof getGlobalsOf(obj as Element)['Element'];
}
export function isHTMLElement(obj: any): obj is HTMLElement {
return obj && (obj instanceof getGlobalsOf(obj)['HTMLElement']);
export function isHTMLElement(obj: unknown): obj is HTMLElement {
return !!obj && obj instanceof getGlobalsOf(obj as Element)['HTMLElement'];
}

@@ -0,1 +1,2 @@

// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference path="../matchers.d.ts" />

@@ -18,3 +19,4 @@

chai.use(isPresent);
if (typeof window !== 'undefined') { // chai-dom's matchers are not Node-safe
if (typeof window !== 'undefined') {
// chai-dom's matchers are not Node-safe
chai.use(chaiDom);

@@ -24,9 +26,9 @@ chai.use(chaiStyle);

const expect = Object.assign(chai.expect.bind(chai), chai.expect) as Chai.ExpectStatic;
const expect: Chai.ExpectStatic = Object.assign(chai.expect.bind(chai), chai.expect);
export * from './helpers'
export * from './layout'
export * from './layout-driver'
export * from './helpers';
export * from './layout';
export * from './layout-driver';
export * from './select-dom';
export { chai, sinon, expect, layout };
import { isElement } from './helpers';
function isPresent(element: any): boolean {
if (isElement(element)) {
const rects = [...element.getClientRects()];
return rects.some(rectangle => rectangle.width > 0 && rectangle.height > 0);
} else {
return false;
}
function isPresent(element: unknown): boolean {
return (
isElement(element) &&
[...element.getClientRects()].some((rectangle) => rectangle.width > 0 && rectangle.height > 0)
);
}
export default function (chai: Chai.ChaiStatic, util: Chai.ChaiUtils) {
chai.Assertion.addMethod('present', function (this: any) {
const { flag } = util;
const element = flag(this, 'object');
this.assert(isPresent(element),
'Element expected to be present.',
'Element expected to be absent.'
);
export default function (chai: Chai.ChaiStatic, { flag }: Chai.ChaiUtils): void {
chai.Assertion.addMethod('present', function () {
const element = flag(this, 'object') as Element;
this.assert(isPresent(element), 'Element expected to be present.', 'Element expected to be absent.', true);
});
chai.Assertion.addMethod('absent', function (this: any) {
const { flag } = util;
const element = flag(this, 'object');
this.assert(!isPresent(element),
'Element expected to be absent.',
'Element expected to be present.'
);
chai.Assertion.addMethod('absent', function () {
const element = flag(this, 'object') as Element;
this.assert(!isPresent(element), 'Element expected to be absent.', 'Element expected to be present.', true);
});
}

@@ -9,3 +9,3 @@ export type Geometry = [number, number, number, number];

type LayoutFixtureMap = { [id: string]: LayoutFixtureMapItem[] }
type LayoutFixtureMap = { [id: string]: LayoutFixtureMapItem[] };

@@ -16,3 +16,3 @@ export function generateMap(source: string): LayoutMap {

const map: LayoutFixtureMap = {};
for (let ch of source) {
for (const ch of source) {
col++;

@@ -30,3 +30,3 @@ if (ch === '\n') {

const geometry: LayoutMap = {};
for (let key in map) {
for (const key in map) {
const record = map[key];

@@ -51,5 +51,5 @@ const x = record[0].col;

const domMap: DomMap = {
container
container,
};
for (let elementId in layoutMap) {
for (const elementId in layoutMap) {
const element = document.createElement('div');

@@ -59,6 +59,6 @@ const geometry: Geometry = layoutMap[elementId];

element.style.position = 'absolute';
element.style.left = geometry[0] + 'px';
element.style.top = geometry[1] + 'px';
element.style.width = geometry[2] + 'px';
element.style.height = geometry[3] + 'px';
element.style.left = `${geometry[0]}px`;
element.style.top = `${geometry[1]}px`;
element.style.width = `${geometry[2]}px`;
element.style.height = `${geometry[3]}px`;
container.appendChild(element);

@@ -65,0 +65,0 @@ domMap[elementId] = element;

@@ -18,11 +18,12 @@ import { isElement } from './helpers';

function isPointInside(pt: Point, boundaries: ClientRect): boolean {
return pt.x >= boundaries.left && pt.x <= boundaries.right &&
pt.y >= boundaries.top && pt.y <= boundaries.bottom;
return pt.x >= boundaries.left && pt.x <= boundaries.right && pt.y >= boundaries.top && pt.y <= boundaries.bottom;
}
function isInside(rect: ClientRect, boundaries: ClientRect): boolean {
return rect.left >= boundaries.left &&
return (
rect.left >= boundaries.left &&
rect.top >= boundaries.top &&
rect.right <= boundaries.right &&
rect.bottom <= boundaries.bottom;
rect.bottom <= boundaries.bottom
);
}

@@ -45,20 +46,24 @@

function findExcludedEdges(edges: number[], range: [number, number]): number[] {
return edges.reduce<number[]>((acc, edge, index) =>
(edge >= range[0] && edge <= range[1])
? acc
: acc.concat(index),
[]);
return edges.reduce<number[]>(
(acc, edge, index) => (edge >= range[0] && edge <= range[1] ? acc : acc.concat(index)),
[]
);
}
function getEdgeMap(edges: number[], tolerance: number): EdgeMapItem[] {
return edges.reduce<EdgeMapItem[]>((acc, edge) => acc.concat(
{ range: [edge, edge + tolerance], excludedEdges: findExcludedEdges(edges, [edge, edge + tolerance]) },
{ range: [edge, edge - tolerance], excludedEdges: findExcludedEdges(edges, [edge, edge - tolerance]) }
), []);
return edges.reduce<EdgeMapItem[]>(
(acc, edge) =>
acc.concat(
{ range: [edge, edge + tolerance], excludedEdges: findExcludedEdges(edges, [edge, edge + tolerance]) },
{ range: [edge, edge - tolerance], excludedEdges: findExcludedEdges(edges, [edge, edge - tolerance]) }
),
[]
);
}
function pickLeastExcludedEdges(edgeMap: EdgeMapItem[]): number[] {
const excludedEdgeItem = edgeMap.reduce<EdgeMapItem | null>((acc, item) =>
(!acc || item.excludedEdges.length < acc.excludedEdges.length) ? item : acc,
null);
const excludedEdgeItem = edgeMap.reduce<EdgeMapItem | null>(
(acc, item) => (!acc || item.excludedEdges.length < acc.excludedEdges.length ? item : acc),
null
);
if (excludedEdgeItem) {

@@ -71,3 +76,3 @@ return excludedEdgeItem.excludedEdges;

export function detectMisalignment(edges: number[], tolerance: number = 0): number[] {
export function detectMisalignment(edges: number[], tolerance = 0): number[] {
const edgeMap = getEdgeMap(edges, tolerance);

@@ -79,4 +84,4 @@ return pickLeastExcludedEdges(edgeMap);

const propsByDirection: { [direction: string]: [BoxProps, BoxProps] } = {
"horizontal": ['right', 'left'],
"vertical": ['bottom', 'top']
horizontal: ['right', 'left'],
vertical: ['bottom', 'top'],
};

@@ -88,10 +93,6 @@

const edgeProps = propsByDirection[direction];
return [
(rect: ClientRect) => rect[edgeProps[0]],
rect => rect[edgeProps[1]]
]
return [(rect: ClientRect) => rect[edgeProps[0]], (rect) => rect[edgeProps[1]]];
}
function findLastElementOfSequence(elements: Element[], direction: Direction, tolerance: number = 1, distance: number = 0): number {
function findLastElementOfSequence(elements: Element[], direction: Direction, tolerance = 1, distance = 0): number {
const [farEdge, nearEdge] = getEdgeAccessors(direction);

@@ -108,84 +109,116 @@ const boundList = elements.map(getBoundaries);

export default function use(chai: Chai.ChaiStatic, util: Chai.ChaiUtils) {
chai.Assertion.addMethod('insideOf', function (this: any, boundaryElement: Element) {
const element = util.flag(this, 'object');
this.assert(isInside(getBoundaries(element), getBoundaries(boundaryElement)),
'Expected element to be inside of the other, but it wasn\'t.',
'Expected element not to be inside of the other, but it was.'
export default function use(chai: Chai.ChaiStatic, util: Chai.ChaiUtils): void {
chai.Assertion.addMethod('insideOf', function (boundaryElement: Element) {
const element = util.flag(this, 'object') as Element;
this.assert(
isInside(getBoundaries(element), getBoundaries(boundaryElement)),
"Expected element to be inside of the other, but it wasn't.",
'Expected element not to be inside of the other, but it was.',
true
);
});
chai.Assertion.addMethod('outsideOf', function (this: any, boundaryElement: Element) {
const element = util.flag(this, 'object');
this.assert(isOutside(getBoundaries(element), getBoundaries(boundaryElement)),
'Expected element to be outside of the other, but it wasn\'t.',
'Expected element not to be outside of the other, but it was.'
chai.Assertion.addMethod('outsideOf', function (boundaryElement: Element) {
const element = util.flag(this, 'object') as Element;
this.assert(
isOutside(getBoundaries(element), getBoundaries(boundaryElement)),
"Expected element to be outside of the other, but it wasn't.",
'Expected element not to be outside of the other, but it was.',
true
);
});
chai.Assertion.addMethod('widerThan', function (this: any, comparedTo: Element) {
const element = util.flag(this, 'object');
this.assert(getBoundaries(element).width > getBoundaries(comparedTo).width,
'Expected element to be wider than the other, but it wasn\'t.',
'Expected element not to be wider than the other, but it was.'
chai.Assertion.addMethod('widerThan', function (comparedTo: Element) {
const element = util.flag(this, 'object') as Element;
this.assert(
getBoundaries(element).width > getBoundaries(comparedTo).width,
"Expected element to be wider than the other, but it wasn't.",
'Expected element not to be wider than the other, but it was.',
true
);
});
chai.Assertion.addMethod('higherThan', function (this: any, comparedTo: Element) {
const element = util.flag(this, 'object');
this.assert(getBoundaries(element).height > getBoundaries(comparedTo).height,
'Expected element to be higher than the other, but it wasn\'t.',
'Expected element not to be higher than the other, but it was.'
chai.Assertion.addMethod('higherThan', function (comparedTo: Element) {
const element = util.flag(this, 'object') as Element;
this.assert(
getBoundaries(element).height > getBoundaries(comparedTo).height,
"Expected element to be higher than the other, but it wasn't.",
'Expected element not to be higher than the other, but it was.',
true
);
});
chai.Assertion.addMethod('biggerThan', function (this: any, comparedTo: Element) {
const element = util.flag(this, 'object');
chai.Assertion.addMethod('biggerThan', function (comparedTo: Element) {
const element = util.flag(this, 'object') as Element;
const elementRect: ClientRect = getBoundaries(element);
const comparedRect: ClientRect = getBoundaries(comparedTo);
this.assert((elementRect.width * elementRect.height) > (comparedRect.width * comparedRect.height),
'Expected element to be bigger than the other, but it wasn\'t.',
'Expected element not to be bigger than the other, but it was.'
this.assert(
elementRect.width * elementRect.height > comparedRect.width * comparedRect.height,
"Expected element to be bigger than the other, but it wasn't.",
'Expected element not to be bigger than the other, but it was.',
true
);
});
function assertAlignment(this: any, direction: Direction, alignment: (VerticalAlignment | HorizontalAlignment), tolerance: number) {
const elementList: Element[] = util.flag(this, 'object');
function assertAlignment(
this: Chai.AssertionStatic,
direction: Direction,
alignment: VerticalAlignment | HorizontalAlignment,
tolerance: number
) {
const elementList = util.flag(this, 'object') as Element[];
if (elementList.length === 0) {
throw new Error(`Expected elements to be ${direction}ly aligned to "${alignment}" but element list was empty`);
throw new Error(
`Expected elements to be ${direction}ly aligned to "${alignment}" but element list was empty`
);
} else if (elementList.length === 1) {
throw new Error(`Expected elements to be ${direction}ly aligned to "${alignment}" but element list had only one element`);
throw new Error(
`Expected elements to be ${direction}ly aligned to "${alignment}" but element list had only one element`
);
}
const property: BoxProps = alignment as BoxProps;
const edges: number[] = alignment === 'center'
? elementList.map(element => {
const rect = getBoundaries(element);
if (direction === "horizontal") {
return (rect.left + rect.right) / 2.0;
} else {
return (rect.top + rect.bottom) / 2.0;
}
})
: elementList.map(element => getBoundaries(element)[property]);
const edges: number[] =
alignment === 'center'
? elementList.map((element) => {
const rect = getBoundaries(element);
if (direction === 'horizontal') {
return (rect.left + rect.right) / 2.0;
} else {
return (rect.top + rect.bottom) / 2.0;
}
})
: elementList.map((element) => getBoundaries(element)[property]);
const misaligned = detectMisalignment(edges, tolerance);
this.assert(misaligned.length === 0,
`Expected elements to be ${direction}ly aligned to "${alignment}" but some weren\'t. ([${misaligned}])`,
`Expected elements not to be ${direction}ly aligned to "${alignment}" but they were.`
)
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
);
}
chai.Assertion.addMethod('verticallyAligned', function (this: any, alignment: VerticalAlignment, tolerance: number = 0) {
assertAlignment.call(this, "vertical", alignment, tolerance);
chai.Assertion.addMethod('verticallyAligned', function (alignment: VerticalAlignment, tolerance = 0) {
assertAlignment.call(this, 'vertical', alignment, tolerance);
});
chai.Assertion.addMethod('horizontallyAligned', function (this: any, alignment: HorizontalAlignment, tolerance: number = 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);
});
function assertSequence(this: any, direction: Direction, tolerance?: number, distanceBetween?: number) {
const elementList = util.flag(this, 'object');
function assertSequence(
this: Chai.AssertionStatic,
direction: Direction,
tolerance?: number,
distanceBetween?: number
) {
const elementList = util.flag(this, 'object') as Element[];

@@ -199,18 +232,21 @@ if (elementList.length === 0) {

const lastElementOfSequence = findLastElementOfSequence(elementList, direction, tolerance, distanceBetween);
this.assert(lastElementOfSequence === elementList.length,
`Expected elements to form ${direction} sequence, but they didn\'t. (${lastElementOfSequence})`,
`Expected elements not to form ${direction} sequence, but they did.`
this.assert(
lastElementOfSequence === elementList.length,
`Expected elements to form ${direction} sequence, but they didn't. (${lastElementOfSequence})`,
`Expected elements not to form ${direction} sequence, but they did.`,
elementList.length,
lastElementOfSequence
);
}
chai.Assertion.addMethod('inHorizontalSequence', function (this: any, options: Options = {}) {
assertSequence.call(this, "horizontal", options.tolerance, options.distance);
chai.Assertion.addMethod('inHorizontalSequence', function (options: Options = {}) {
assertSequence.call(this, 'horizontal', options.tolerance, options.distance);
});
chai.Assertion.addMethod('inVerticalSequence', function (this: any, options: Options = {}) {
assertSequence.call(this, "vertical", options.tolerance, options.distance);
chai.Assertion.addMethod('inVerticalSequence', function (options: Options = {}) {
assertSequence.call(this, 'vertical', options.tolerance, options.distance);
});
chai.Assertion.addProperty('width', function (this: any) {
const element = util.flag(this, 'object');
chai.Assertion.addProperty('width', function () {
const element = util.flag(this, 'object') as Element;
const size = getBoundaries(element).width;

@@ -222,12 +258,12 @@ util.flag(this, 'object', size);

function layoutProperty(propName: keyof ClientRect) {
return function (this: any) {
const element = util.flag(this, 'object');
return function (this: Chai.AssertionStatic) {
const element = util.flag(this, 'object') as Element;
const size = getBoundaries(element)[propName];
util.flag(this, 'object', size);
util.flag(this, 'layout', propName);
}
};
}
function compare(_super: any) {
return function (this: any, x: number | Element) {
function compare(_super: (this: Chai.AssertionStatic, x: number | Element) => void) {
return function (this: Chai.AssertionStatic, x: number | Element) {
const layout: BoxProps = util.flag(this, 'layout') as BoxProps;

@@ -239,7 +275,6 @@ if (layout && isElement(x)) {

}
}
};
}
const propList: Array<keyof ClientRect> = ['width', 'height', 'top', 'bottom', 'left', 'right'];
propList.forEach(propName => chai.Assertion.addProperty(propName, layoutProperty(propName)));
propList.forEach((propName) => chai.Assertion.addProperty(propName, layoutProperty(propName)));

@@ -246,0 +281,0 @@ chai.Assertion.overwriteMethod('greaterThan', compare);

import matches from 'dom-matches';
export function selectDom(container: Element, attrName: string = 'data-automation-id') {
export function selectDom(
container: Element,
attrName = 'data-automation-id'
): (...selectors: string[]) => Element | null {
function select(parentElement: Element, ...selectors: string[]): Element | null {

@@ -28,5 +30,5 @@ const [selector, ...rest] = selectors;

return function (...selectors: string[]) {
return function (...selectors: string[]): Element | null {
return select(container, ...selectors);
}
};
}

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

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

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc