test-drive
Advanced tools
Comparing version 0.0.56 to 0.0.57
@@ -61,7 +61,10 @@ "use strict"; | ||
} | ||
function findLastElementOfSequence(elements, direction, tolerance) { | ||
function findLastElementOfSequence(elements, direction, tolerance, distance) { | ||
if (tolerance === void 0) { tolerance = 1; } | ||
if (distance === void 0) { distance = 0; } | ||
var _a = getEdgeAccessors(direction), farEdge = _a[0], nearEdge = _a[1]; | ||
var boundList = elements.map(getBoundaries); | ||
for (var i = 0; i < boundList.length - 1; i++) { | ||
if (nearEdge(boundList[i + 1]) - farEdge(boundList[i]) > tolerance) { | ||
var distanceBetweenElements = nearEdge(boundList[i + 1]) - farEdge(boundList[i]); | ||
if (Math.abs(distanceBetweenElements - distance) > tolerance) { | ||
return i + 1; | ||
@@ -126,3 +129,3 @@ } | ||
}); | ||
function assertSequence(tolerance, direction) { | ||
function assertSequence(tolerance, distanceBetween, direction) { | ||
var elementList = util.flag(this, 'object'); | ||
@@ -135,12 +138,12 @@ if (elementList.length === 0) { | ||
} | ||
var lastElementOfSequence = findLastElementOfSequence(elementList, direction, tolerance); | ||
var 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."); | ||
} | ||
chai.Assertion.addMethod('inHorizontalSequence', function (tolerance) { | ||
if (tolerance === void 0) { tolerance = 1.0; } | ||
assertSequence.call(this, tolerance, "horizontal"); | ||
chai.Assertion.addMethod('inHorizontalSequence', function (options) { | ||
if (options === void 0) { options = {}; } | ||
assertSequence.call(this, options.tolerance, options.distance, "horizontal"); | ||
}); | ||
chai.Assertion.addMethod('inVerticalSequence', function (tolerance) { | ||
if (tolerance === void 0) { tolerance = 1.0; } | ||
assertSequence.call(this, tolerance, "vertical"); | ||
chai.Assertion.addMethod('inVerticalSequence', function (options) { | ||
if (options === void 0) { options = {}; } | ||
assertSequence.call(this, options.tolerance, options.distance, "vertical"); | ||
}); | ||
@@ -147,0 +150,0 @@ chai.Assertion.addProperty('width', function () { |
type VerticalAlignment = 'top' | 'center' | 'bottom'; | ||
type HorizontalAlignment = 'left' | 'center' | 'right'; | ||
interface Options { | ||
tolerance?: number; | ||
distance?: number; | ||
} | ||
@@ -17,4 +21,4 @@ declare module Chai { | ||
horizontallyAligned(alignment: HorizontalAlignment, tolerance?: number): Assertion; | ||
inHorizontalSequence(tolerance?: number): Assertion; | ||
inVerticalSequence(tolerance?: number): Assertion; | ||
inHorizontalSequence(options?: Options): Assertion; | ||
inVerticalSequence(options?: Options): Assertion; | ||
@@ -21,0 +25,0 @@ width: Assertion; |
{ | ||
"name": "test-drive", | ||
"version": "0.0.56", | ||
"version": "0.0.57", | ||
"description": "Opinionated library for writing web component tests", | ||
@@ -5,0 +5,0 @@ "main": "./dist/src/index.js", |
@@ -91,8 +91,9 @@ | ||
function findLastElementOfSequence(elements: Element[], direction: Direction, tolerance: number): number { | ||
function findLastElementOfSequence(elements: Element[], direction: Direction, tolerance: number = 1, distance: number = 0): number { | ||
const [farEdge, nearEdge] = getEdgeAccessors(direction); | ||
const boundList = elements.map(getBoundaries); | ||
for(let i=0; i<boundList.length-1; i++) { | ||
if(nearEdge(boundList[i+1]) - farEdge(boundList[i]) > tolerance) { | ||
return i+1; | ||
const distanceBetweenElements = nearEdge(boundList[i+1]) - farEdge(boundList[i]); | ||
if (Math.abs(distanceBetweenElements - distance) > tolerance) { | ||
return i + 1; | ||
} | ||
@@ -183,3 +184,3 @@ } | ||
function assertSequence(tolerance: number, direction: Direction) { | ||
function assertSequence(tolerance: number, distanceBetween: number, direction: Direction) { | ||
const elementList = util.flag(this, 'object'); | ||
@@ -193,3 +194,3 @@ | ||
const lastElementOfSequence = findLastElementOfSequence(elementList, direction, tolerance); | ||
const lastElementOfSequence = findLastElementOfSequence(elementList, direction, tolerance, distanceBetween); | ||
this.assert(lastElementOfSequence === elementList.length, | ||
@@ -201,8 +202,8 @@ `Expected elements to form ${direction} sequence, but they didn\'t. (${lastElementOfSequence})`, | ||
chai.Assertion.addMethod('inHorizontalSequence', function (tolerance: number = 1.0) { | ||
assertSequence.call(this, tolerance, "horizontal"); | ||
chai.Assertion.addMethod('inHorizontalSequence', function (options: Options = {}) { | ||
assertSequence.call(this, options.tolerance, options.distance, "horizontal"); | ||
}); | ||
chai.Assertion.addMethod('inVerticalSequence', function (tolerance: number = 1.0) { | ||
assertSequence.call(this, tolerance, "vertical"); | ||
chai.Assertion.addMethod('inVerticalSequence', function (options: Options = {}) { | ||
assertSequence.call(this, options.tolerance, options.distance, "vertical"); | ||
}); | ||
@@ -209,0 +210,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
3232263
13260