jasmine-dom-spec
Advanced tools
Comparing version 0.7.0 to 0.8.0
{ | ||
"name": "jasmine-dom-spec", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"authors": [ | ||
@@ -5,0 +5,0 @@ "Mickael Jeanroy" |
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014-2022 Mickael Jeanroy | ||
* Copyright (c) 2014-2024 Mickael Jeanroy | ||
* | ||
@@ -25,2 +25,4 @@ * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
/* eslint-disable no-use-before-define */ | ||
type NodeId = string | RegExp | jasmine.Any; | ||
@@ -27,0 +29,0 @@ type NodeTagName = string | RegExp | jasmine.Any; |
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2014-2022 Mickael Jeanroy | ||
* Copyright (c) 2014-2024 Mickael Jeanroy | ||
* | ||
@@ -30,3 +30,2 @@ * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
var _version = jasmine.version_ || jasmine.version; | ||
if (_version.major) { | ||
@@ -37,2 +36,3 @@ _version = _version.major; | ||
} | ||
/** | ||
@@ -42,7 +42,6 @@ * Major version of Jasmine being imported. | ||
*/ | ||
var version = _version; | ||
var PLACEHOLDER = '[NOT]'; | ||
/** | ||
@@ -57,3 +56,2 @@ * Return message with the appropriate negation: | ||
*/ | ||
function negateMessage(isNot, message) { | ||
@@ -63,3 +61,2 @@ if (!message) { | ||
} | ||
var notKey = isNot ? PLACEHOLDER : PLACEHOLDER + " "; | ||
@@ -91,2 +88,12 @@ var notValue = isNot ? 'not' : ''; | ||
/** | ||
* Check that a given value is NIL (`null` or `undefined`). | ||
* | ||
* @param {*} obj Value to check. | ||
* @return {boolean} `true` if `obj` is `null` or `undefined`, `false` otherwise. | ||
*/ | ||
function isNil(obj) { | ||
return isNull(obj) || isUndefined(obj); | ||
} | ||
/** | ||
* Check that a given value is an object. | ||
@@ -97,3 +104,2 @@ * | ||
*/ | ||
function isObject(obj) { | ||
@@ -107,4 +113,4 @@ return !isNull(obj) && typeof obj === 'object'; | ||
*/ | ||
var ELEMENT_NODE = 1; | ||
var ELEMENT_NODE = 1; | ||
/** | ||
@@ -116,8 +122,6 @@ * Check if an object is a DOM node. | ||
*/ | ||
function isDomElement(actual) { | ||
if (isNull(actual) || isUndefined(actual)) { | ||
if (isNil(actual)) { | ||
return false; | ||
} | ||
return isObject(actual) && actual.nodeType === ELEMENT_NODE; | ||
@@ -133,3 +137,2 @@ } | ||
*/ | ||
function pp(value, _pp) { | ||
@@ -157,3 +160,2 @@ try { | ||
*/ | ||
function jasmine1MatcherFactory(fn) { | ||
@@ -167,10 +169,10 @@ /** | ||
// The `this` object is equals to the current test context. | ||
// eslint-disable-next-line no-invalid-this | ||
var env = this.env; // eslint-disable-next-line no-invalid-this | ||
var env = this.env, | ||
actual = this.actual, | ||
isNot = this.isNot; | ||
var equals_ = this.env.equals_; // eslint-disable-next-line no-invalid-this | ||
var actual = this.actual; // eslint-disable-next-line no-invalid-this | ||
var isNot = this.isNot; | ||
// eslint-disable-next-line no-invalid-this | ||
var equals_ = this.env.equals_; | ||
var ctx = { | ||
@@ -184,3 +186,2 @@ actual: actual, | ||
} | ||
return equals_.apply(env, equalsArgs); | ||
@@ -193,12 +194,9 @@ }, | ||
}; | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var result = fn.apply(ctx, [ctx].concat(args)); | ||
var pass = isNot ? !result.pass : result.pass; | ||
if (!pass) { | ||
// eslint-disable-next-line no-invalid-this | ||
// eslint-disable-next-line no-invalid-this,func-names | ||
this.message = function() { | ||
@@ -208,3 +206,2 @@ return negateMessage(isNot, result.message()); | ||
} | ||
return pass; | ||
@@ -224,3 +221,2 @@ }; | ||
*/ | ||
function jasmine2MatcherFactory(fn) { | ||
@@ -259,7 +255,5 @@ /** | ||
ctx.isNot = false; | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
var result = fn.apply(void 0, [ctx].concat(args)); | ||
@@ -273,3 +267,2 @@ return { | ||
}, | ||
/** | ||
@@ -286,7 +279,5 @@ * Jasmine2 compare function that will be called when a custom matcher is used with: | ||
ctx.isNot = true; | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
var result = fn.apply(void 0, [ctx].concat(args)); | ||
@@ -314,3 +305,2 @@ return { | ||
*/ | ||
function jasmine3MatcherFactory(fn) { | ||
@@ -328,3 +318,2 @@ /** | ||
} | ||
var customEqualityTesters = args[0] && !args[0].deprecated ? args[0] : undefined; | ||
@@ -348,3 +337,3 @@ var ctx = { | ||
* @param {*} actual Object being tested (the object being given in `expect` call). | ||
* @param {Array<*>} args The matcher arguments (arguments being given to `toCustomMatcher` call). | ||
* @param {Array<*>} compareArgs The matcher arguments (arguments being given to `toCustomMatcher` call). | ||
* @return {Object} The test result. | ||
@@ -355,8 +344,6 @@ */ | ||
ctx.isNot = false; | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
for (var _len2 = arguments.length, compareArgs = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
compareArgs[_key2 - 1] = arguments[_key2]; | ||
} | ||
var result = fn.apply(void 0, [ctx].concat(args)); | ||
var result = fn.apply(void 0, [ctx].concat(compareArgs)); | ||
return { | ||
@@ -369,3 +356,2 @@ pass: result.pass, | ||
}, | ||
/** | ||
@@ -376,3 +362,3 @@ * Jasmine2 compare function that will be called when a custom matcher is used with: | ||
* @param {*} actual Object being tested (the object being given in `expect` call). | ||
* @param {Array<*>} args The matcher arguments (arguments being given to `toCustomMatcher` call). | ||
* @param {Array<*>} compareArgs The matcher arguments (arguments being given to `toCustomMatcher` call). | ||
* @return {void} | ||
@@ -383,8 +369,6 @@ */ | ||
ctx.isNot = true; | ||
for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
args[_key3 - 1] = arguments[_key3]; | ||
for (var _len3 = arguments.length, compareArgs = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { | ||
compareArgs[_key3 - 1] = arguments[_key3]; | ||
} | ||
var result = fn.apply(void 0, [ctx].concat(args)); | ||
var result = fn.apply(void 0, [ctx].concat(compareArgs)); | ||
return { | ||
@@ -410,3 +394,2 @@ pass: !result.pass, | ||
*/ | ||
function jasmine4MatcherFactory(fn) { | ||
@@ -442,7 +425,5 @@ /** | ||
ctx.isNot = false; | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
var result = fn.apply(void 0, [ctx].concat(args)); | ||
@@ -456,3 +437,2 @@ return { | ||
}, | ||
/** | ||
@@ -469,7 +449,5 @@ * Jasmine2 compare function that will be called when a custom matcher is used with: | ||
ctx.isNot = true; | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
var result = fn.apply(void 0, [ctx].concat(args)); | ||
@@ -493,2 +471,3 @@ return { | ||
}; | ||
/** | ||
@@ -501,3 +480,2 @@ * Create Jasmine matcher. | ||
*/ | ||
function createMatcher(matcher) { | ||
@@ -538,5 +516,7 @@ return (factories[version] || jasmine4MatcherFactory)(matcher); | ||
// Use a fallback for `Object.keys` if needed (for old browsers). | ||
var objectKeys = Object.keys || function _keys(o) { | ||
var results = []; | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (var key in o) { | ||
@@ -547,5 +527,5 @@ if (has(o, key)) { | ||
} | ||
return results; | ||
}; | ||
/** | ||
@@ -557,4 +537,2 @@ * Get all own and enumerable keys of an object. | ||
*/ | ||
function keys(obj) { | ||
@@ -583,3 +561,2 @@ return objectKeys(obj); | ||
*/ | ||
function ensureHasIn(o, prop, message) { | ||
@@ -589,3 +566,2 @@ if (!hasIn(o, prop)) { | ||
} | ||
return o; | ||
@@ -600,30 +576,30 @@ } | ||
*/ | ||
function tagName(obj) { | ||
// Handle null and undefined since it may fail on some browser. | ||
if (isNull(obj)) { | ||
return '[object Null]'; | ||
} | ||
if (isUndefined(obj)) { | ||
return '[object Undefined]'; | ||
} | ||
var tag = Object.prototype.toString.call(obj); | ||
var tag = Object.prototype.toString.call(obj); // IE11 on Win10 returns `[object Object]` with `Map` and `Set`. | ||
// IE11 on Win10 returns `[object Object]` with `Map` and `Set`. | ||
// IE8 returns `[object Object]` with NodeList and HTMLCollection. | ||
// Try to patch this bug and return the appropriate tag value. | ||
if (tag === '[object Object]') { | ||
// -- IE8 Patch | ||
// Handle NodeList (IE8 only). | ||
if (obj instanceof NodeList) { | ||
return '[object NodeList]'; | ||
} // Handle HTMLCollection (IE8 only). | ||
} | ||
// Handle HTMLCollection (IE8 only). | ||
if (obj instanceof HTMLCollection) { | ||
return '[object HTMLCollection]'; | ||
} // Handle HTMLCollection (IE8 only). | ||
} | ||
// Handle HTMLCollection (IE8 only). | ||
if (has(obj, 'callee')) { | ||
@@ -633,3 +609,2 @@ return '[object Arguments]'; | ||
} | ||
return tag; | ||
@@ -647,3 +622,2 @@ } | ||
*/ | ||
function is(obj, type) { | ||
@@ -653,52 +627,17 @@ return tagName(obj) === "[object " + type + "]"; | ||
var _isArray = Array.isArray || function _isArray(obj) { | ||
return is(obj, 'Array'); | ||
}; | ||
/** | ||
* Check that a given value is a string. | ||
* Check that a given value is an array. | ||
* | ||
* @param {*} obj Value to check. | ||
* @return {boolean} `true` if `obj` is a string, `false` otherwise. | ||
* @return {boolean} `true` if `obj` is an array, `false` otherwise. | ||
*/ | ||
function isString(obj) { | ||
return is(obj, 'String'); | ||
function isArray(obj) { | ||
return _isArray(obj); | ||
} | ||
/** | ||
* Check if the parameter is a node list (i.e collections of nodes such as | ||
* those returned by properties such as `Node.childNodes` and | ||
* the `document.querySelectorAll()` method) or an HTML Collection (i.e a | ||
* generic collection (array-like object similar to `arguments`) of | ||
* elements (in document order)). | ||
* | ||
* @param {*} obj Object to test. | ||
* @return {boolean} `true` if `obj` is a `NodeList` or an `HTMLCollection`, `false` otherwise. | ||
*/ | ||
function isNodeCollection(obj) { | ||
return is(obj, 'NodeList') || is(obj, 'HTMLCollection'); | ||
} | ||
/** | ||
* Check that a predicate satisfies each elements in an array. | ||
* | ||
* The predicate function will be called with three arguments: | ||
* - `value` The value for the given iteration. | ||
* - `key` The key of the value being iterated. | ||
* - `array` The array being traversed. | ||
* | ||
* @param {Array} array The array to iterate. | ||
* @param {function} predicate The predicate function. | ||
* @return {boolean} `true` if the predicate returns a truthy value for each element | ||
* in the array, `false` otherwise. | ||
*/ | ||
function every(array, predicate) { | ||
for (var i = 0, size = array.length; i < size; ++i) { | ||
if (!predicate.call(null, array[i], i, array)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
/** | ||
* Check that a given value is a function. | ||
@@ -709,3 +648,2 @@ * | ||
*/ | ||
function isFunction(value) { | ||
@@ -721,3 +659,2 @@ return is(value, 'Function'); | ||
*/ | ||
function isNumber(obj) { | ||
@@ -727,55 +664,35 @@ return is(obj, 'Number'); | ||
/* global jQuery */ | ||
// An object with these methods will be considered a jQuery object. | ||
var JQ_METHODS = ['addClass', 'prop', 'attr', 'html', 'text']; | ||
/** | ||
* Check if the parameter is an HTML collection (i.e a generic collection (array-like | ||
* object similar to `arguments`) of elements (in document order)). | ||
* | ||
* @param {*} obj Object to test. | ||
* @return {boolean} `true` if `obj` is an `HTMLCollection`, `false` otherwise. | ||
*/ | ||
function isJqueryObject(obj) { | ||
// Fail fast with `primitive types`. | ||
if (!isObject(obj)) { | ||
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991; | ||
function isArrayLike(value) { | ||
if (isNil(value) || isFunction(value)) { | ||
return false; | ||
} // If `obj` is an instance of global jQuery, we are sure it is a jQuery object. | ||
if (isJqueryGloballyAvailable() && obj instanceof jQuery) { | ||
} | ||
if (isArray(value)) { | ||
return true; | ||
} // Use duck-typing ; each jQuery instances should have: | ||
// - A `length` property that is a `number` greater than or equal to zero. | ||
// - Mandatory methods listed below. | ||
} | ||
return isNumber(value.length) && value.length > -1 && value.length % 1 === 0 && value.length <= MAX_SAFE_INTEGER; | ||
} | ||
return isNumber(obj.length) && obj.length >= 0 && every(JQ_METHODS, function(x) { | ||
return isFunction(obj[x]); | ||
}); | ||
} | ||
/** | ||
* Check if `jQuery` is globally available (i.e available on `window` object). | ||
* Check that a given value is a string. | ||
* | ||
* @return {boolean} `true` if `jQuery` is globally available, `false` otherwise. | ||
* @param {*} obj Value to check. | ||
* @return {boolean} `true` if `obj` is a string, `false` otherwise. | ||
*/ | ||
function isJqueryGloballyAvailable() { | ||
return typeof jQuery !== 'undefined'; | ||
function isString(obj) { | ||
return is(obj, 'String'); | ||
} | ||
var _isArray = Array.isArray || function _isArray(obj) { | ||
return is(obj, 'Array'); | ||
}; | ||
/** | ||
* Check that a given value is an array. | ||
* Check if the parameter is a node list (i.e collections of nodes such as | ||
* those returned by properties such as `Node.childNodes` and | ||
* the `document.querySelectorAll()` method) or an HTML Collection (i.e a | ||
* generic collection (array-like object similar to `arguments`) of | ||
* elements (in document order)). | ||
* | ||
* @param {*} obj Value to check. | ||
* @return {boolean} `true` if `obj` is an array, `false` otherwise. | ||
* @param {*} obj Object to test. | ||
* @return {boolean} `true` if `obj` is a `NodeList` or an `HTMLCollection`, `false` otherwise. | ||
*/ | ||
function isArray(obj) { | ||
return _isArray(obj); | ||
function isNodeCollection(obj) { | ||
return is(obj, 'NodeList') || is(obj, 'HTMLCollection'); | ||
} | ||
@@ -792,3 +709,2 @@ | ||
*/ | ||
function toDomElement(value, pp) { | ||
@@ -798,12 +714,65 @@ if (isDomElement(value)) { | ||
} | ||
var nodes = isString(value) ? createNodes(value) : value; | ||
if (isNodeCollection(nodes) || isJqueryObject(nodes) || isArray(nodes)) { | ||
return extractSingleNode(nodes, pp); | ||
var maybeDomNode = isNodeCollection(nodes) || isArrayLike(nodes) ? extractSingleNode(nodes, pp) : nodes; | ||
if (isDomElement(maybeDomNode)) { | ||
return maybeDomNode; | ||
} | ||
var unwrappedDomNode = unwrapDomNode(maybeDomNode); | ||
if (!unwrappedDomNode) { | ||
throw new Error("Expect DOM node but found: " + pp(value)); | ||
} | ||
return unwrappedDomNode; | ||
} | ||
throw new Error("Expect DOM node but found: " + pp(value)); | ||
/** | ||
* Unwrap angular `DebugElement` to return associated native DOM node. | ||
* | ||
* @param {*} value Angular `DebugElement` | ||
* @returns {*} DOM Node if `value` is a `DebugElement`, or something else. | ||
*/ | ||
function unwrapNgDebugElement(value) { | ||
return value.nativeElement; | ||
} | ||
/** | ||
* Unwrap angular `VueWrapper` to return associated native DOM node. | ||
* | ||
* @param {*} value Vue `VueWrapper` | ||
* @returns {*} DOM Node if `value` is a `VueWrapper`, or something else. | ||
*/ | ||
function unwrapVueWrapper(value) { | ||
return value.element; | ||
} | ||
/** | ||
* Unwrap render result of react-testing-library to return associated native DOM node. | ||
* | ||
* @param {*} value Result of react-testing-library `render`. | ||
* @returns {*} DOM Node if `value` is the result of react-testing-library `render`, or something else. | ||
*/ | ||
function unwrapReactTestingLibraryResult(value) { | ||
return value.baseElement; | ||
} | ||
var unwrapFunctions = [unwrapNgDebugElement, unwrapVueWrapper, unwrapReactTestingLibraryResult]; | ||
/** | ||
* Try to unwrap DOM Node from given structure. | ||
* | ||
* @param {*} wrapper DOM Node wrapper. | ||
* @returns {HTMLElement | null} The unwrapped DOM node, `null` otherwise. | ||
*/ | ||
function unwrapDomNode(wrapper) { | ||
if (isNil(wrapper)) { | ||
return null; | ||
} | ||
for (var i = 0; i < unwrapFunctions.length; ++i) { | ||
var unwrappedNode = unwrapFunctions[i](wrapper); | ||
if (isDomElement(unwrappedNode)) { | ||
return unwrappedNode; | ||
} | ||
} | ||
return null; | ||
} | ||
/** | ||
* Translate HTML content to a `NodeList` element. | ||
@@ -814,3 +783,2 @@ * | ||
*/ | ||
function createNodes(html) { | ||
@@ -821,2 +789,3 @@ var div = document.createElement('div'); | ||
} | ||
/** | ||
@@ -831,22 +800,11 @@ * Extract DOM from singleton array-like object and: | ||
*/ | ||
function extractSingleNode(value, pp) { | ||
var size = value.length; | ||
if (size === 0) { | ||
throw new Error('Expect valid node but found empty node list'); | ||
} | ||
if (size > 1) { | ||
throw new Error("Expect single node but found node list of " + size + " nodes: " + pp(value)); | ||
} | ||
var node = value[0]; | ||
if (!isDomElement(node)) { | ||
throw new Error("Expect single node but found value: " + pp(value)); | ||
} | ||
return node; | ||
return value[0]; | ||
} | ||
@@ -869,3 +827,2 @@ | ||
*/ | ||
function toBeChecked(_ref) { | ||
@@ -899,3 +856,2 @@ var actual = _ref.actual, | ||
*/ | ||
function toBeDetachedElement(_ref) { | ||
@@ -907,3 +863,2 @@ var actual = _ref.actual, | ||
var parentNode = node; | ||
while (parentNode) { | ||
@@ -914,6 +869,4 @@ if (parentNode === document || parentNode === document.body) { | ||
} | ||
parentNode = parentNode.parentNode; | ||
} | ||
return { | ||
@@ -941,3 +894,2 @@ pass: isDetached, | ||
*/ | ||
function toBeDisabled(_ref) { | ||
@@ -983,3 +935,2 @@ var actual = _ref.actual, | ||
*/ | ||
function toBeDisplayed(_ref) { | ||
@@ -999,2 +950,3 @@ var actual = _ref.actual, | ||
} | ||
/** | ||
@@ -1006,3 +958,2 @@ * Get the value of the `display` css property on given node. | ||
*/ | ||
function getCurrentDisplayStyleValue(node) { | ||
@@ -1012,13 +963,14 @@ // Modern browsers. | ||
return getComputedDisplayStyle(node); | ||
} // IE8 does not support `getComputedStyle` method. | ||
} | ||
// IE8 does not support `getComputedStyle` method. | ||
if (isIn(node, 'currentStyle')) { | ||
return getCurrentDisplayStyle(node); | ||
} // If we are here, then it's weird since `getComputedStyle` and `currentStyle` are not supported. | ||
} | ||
// If we are here, then it's weird since `getComputedStyle` and `currentStyle` are not supported. | ||
// Use the `style` property as a fallback. | ||
return node.style.display; | ||
} | ||
/** | ||
@@ -1033,4 +985,2 @@ * Extract the computed value of the `display` style property. | ||
*/ | ||
function getComputedDisplayStyle(node) { | ||
@@ -1045,2 +995,3 @@ try { | ||
} | ||
/** | ||
@@ -1056,4 +1007,2 @@ * Extract the current style value of the `display` style property. | ||
*/ | ||
function getCurrentDisplayStyle(node) { | ||
@@ -1083,3 +1032,2 @@ try { | ||
*/ | ||
function toBeFocused(_ref) { | ||
@@ -1089,3 +1037,4 @@ var actual = _ref.actual, | ||
var node = toDomElement(actual, pp); | ||
var activeElement = document.activeElement; | ||
var _document = document, | ||
activeElement = _document.activeElement; | ||
return { | ||
@@ -1114,3 +1063,2 @@ pass: activeElement === node, | ||
*/ | ||
function toBeIndeterminate(_ref) { | ||
@@ -1143,3 +1091,2 @@ var actual = _ref.actual, | ||
*/ | ||
function toBeRequired(_ref) { | ||
@@ -1172,3 +1119,2 @@ var actual = _ref.actual, | ||
*/ | ||
function toBeSelected(_ref) { | ||
@@ -1188,13 +1134,2 @@ var actual = _ref.actual, | ||
/** | ||
* Check that a given value is NIL (`null` or `undefined`). | ||
* | ||
* @param {*} obj Value to check. | ||
* @return {boolean} `true` if `obj` is `null` or `undefined`, `false` otherwise. | ||
*/ | ||
function isNil(obj) { | ||
return isNull(obj) || isUndefined(obj); | ||
} | ||
/** | ||
* Check if a value is a regexp instance. | ||
@@ -1205,3 +1140,2 @@ * | ||
*/ | ||
function isRegExp(value) { | ||
@@ -1220,3 +1154,2 @@ return is(value, 'RegExp'); | ||
*/ | ||
function matchOrEquals(actual, expected, equalsFn) { | ||
@@ -1228,3 +1161,2 @@ if (isRegExp(expected)) { | ||
} | ||
return equalsFn(actual, expected); | ||
@@ -1250,3 +1182,2 @@ } | ||
*/ | ||
function toHaveId(_ref, id) { | ||
@@ -1271,2 +1202,24 @@ var actual = _ref.actual, | ||
/** | ||
* Check that a predicate satisfies each elements in an array. | ||
* | ||
* The predicate function will be called with three arguments: | ||
* - `value` The value for the given iteration. | ||
* - `key` The key of the value being iterated. | ||
* - `array` The array being traversed. | ||
* | ||
* @param {Array} array The array to iterate. | ||
* @param {function} predicate The predicate function. | ||
* @return {boolean} `true` if the predicate returns a truthy value for each element | ||
* in the array, `false` otherwise. | ||
*/ | ||
function every(array, predicate) { | ||
for (var i = 0, size = array.length; i < size; ++i) { | ||
if (!predicate.call(null, array[i], i, array)) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
/** | ||
* Check that the tested object has expected attributes. | ||
@@ -1291,6 +1244,4 @@ * | ||
*/ | ||
function toHaveAttrs(_ref, attrName, attrValue) { | ||
var _ref2; | ||
var actual = _ref.actual, | ||
@@ -1306,9 +1257,6 @@ equals = _ref.equals, | ||
} | ||
var expectedValue = expected[attr]; | ||
if (isUndefined(expectedValue)) { | ||
return true; | ||
} | ||
var actualValue = node.getAttribute(attr); | ||
@@ -1340,3 +1288,2 @@ return matchOrEquals(actualValue, expectedValue, equals); | ||
var results = []; | ||
for (var i = 0, size = array.length; i < size; ++i) { | ||
@@ -1347,3 +1294,2 @@ if (predicate.call(null, array[i], i, array)) { | ||
} | ||
return results; | ||
@@ -1362,7 +1308,5 @@ } | ||
var size = array.length; | ||
for (var i = 0; i < size; ++i) { | ||
map[iteratee(array[i], i, array)] = array[i]; | ||
} | ||
return map; | ||
@@ -1396,7 +1340,5 @@ } | ||
var results = []; | ||
for (var i = 0, size = array.length; i < size; ++i) { | ||
results.push(iteratee.call(null, array[i], i, array)); | ||
} | ||
return results; | ||
@@ -1424,3 +1366,2 @@ } | ||
} | ||
return false; | ||
@@ -1430,2 +1371,3 @@ } | ||
var _trim = String.prototype.trim; | ||
/** | ||
@@ -1437,3 +1379,2 @@ * Trim a string (use native String#trim function if available). | ||
*/ | ||
function trim(str) { | ||
@@ -1443,3 +1384,2 @@ if (_trim) { | ||
} | ||
return str.replace(/^\s+|\s+$/g, ''); | ||
@@ -1470,3 +1410,2 @@ } | ||
*/ | ||
function toHaveCssClass(_ref, expected) { | ||
@@ -1491,2 +1430,3 @@ var actual = _ref.actual, | ||
} | ||
/** | ||
@@ -1497,3 +1437,2 @@ * Extract array of all css classes, removing useless whitespaces. | ||
*/ | ||
function extract(classes) { | ||
@@ -1503,3 +1442,2 @@ if (isRegExp(classes)) { | ||
} | ||
var arrayOfClasses = classes.split(' '); | ||
@@ -1513,2 +1451,3 @@ var trimmedClasses = map(arrayOfClasses, function(x) { | ||
} | ||
/** | ||
@@ -1522,8 +1461,6 @@ * Check if the given regexp match at least one element in the | ||
*/ | ||
function matchOne(array, regexp) { | ||
return some(array, function(x) { | ||
return matchOrEquals(x, regexp, function(x, y) { | ||
return x === y; | ||
return matchOrEquals(x, regexp, function(x1, x2) { | ||
return x1 === x2; | ||
}); | ||
@@ -1539,3 +1476,2 @@ }); | ||
*/ | ||
function isBoolean(obj) { | ||
@@ -1554,3 +1490,2 @@ return obj === true || obj === false || is(obj, 'Boolean'); | ||
*/ | ||
function isPrimitive(obj) { | ||
@@ -1579,3 +1514,2 @@ return isString(obj) || isNumber(obj) || isBoolean(obj); | ||
*/ | ||
function toHaveHtml(_ref, html) { | ||
@@ -1586,5 +1520,6 @@ var actual = _ref.actual, | ||
var node = toDomElement(actual, pp); | ||
var actualHtml = node.innerHTML; // Html may be a string **or** a jasmine asymetric matcher object. | ||
var actualHtml = node.innerHTML; | ||
// Html may be a string **or** a jasmine asymetric matcher object. | ||
// In the last case, do not try to normalize HTML. | ||
var expectedHtml = isPrimitive(html) ? normalizeHtml(html.toString()) : html; | ||
@@ -1599,2 +1534,3 @@ var ok = matchOrEquals(actualHtml, expectedHtml, equals); | ||
} | ||
/** | ||
@@ -1608,3 +1544,2 @@ * Normalize HTML to be able to compare HTML content | ||
*/ | ||
function normalizeHtml(html) { | ||
@@ -1638,6 +1573,4 @@ var fragment = document.createElement('div'); | ||
*/ | ||
function toHaveProps(_ref, propName, propValue) { | ||
var _ref2; | ||
var actual = _ref.actual, | ||
@@ -1671,9 +1604,6 @@ equals = _ref.equals, | ||
} | ||
var result = ''; | ||
var turnToUpper = false; | ||
for (var i = 0, size = value.length; i < size; ++i) { | ||
var c = value.charAt(i); | ||
if (c === '-') { | ||
@@ -1686,3 +1616,2 @@ turnToUpper = true; | ||
} | ||
return result; | ||
@@ -1713,6 +1642,4 @@ } | ||
*/ | ||
function toHaveStyle(_ref, styleName, styleValue) { | ||
var _ref2; | ||
var actual = _ref.actual, | ||
@@ -1745,3 +1672,2 @@ equals = _ref.equals, | ||
*/ | ||
function toLower(value) { | ||
@@ -1767,3 +1693,2 @@ return isString(value) ? value.toLowerCase() : value; | ||
*/ | ||
function toHaveTagName(_ref, tagName) { | ||
@@ -1807,3 +1732,2 @@ var actual = _ref.actual, | ||
*/ | ||
function toHaveText(_ref, text) { | ||
@@ -1817,3 +1741,3 @@ var actual = _ref.actual, | ||
var expectedText = isPrimitive(text) ? text.toString() : text; | ||
var ok = matchOrEquals(actualText, expectedText, equals); | ||
var ok = matchOrEquals(normalizeTextContent(actualText), normalizeTextContent(expectedText), equals); | ||
return { | ||
@@ -1828,2 +1752,12 @@ pass: ok, | ||
/** | ||
* Normalize text content by trimming it if it is a string. | ||
* | ||
* @param {String|Number|Boolean|RegExp|jasmine.Any|jasmine.Anything} text The text to normalize. | ||
* @returns {string|*} The normalized output. | ||
*/ | ||
function normalizeTextContent(text) { | ||
return isString(text) ? trim(text) : text; | ||
} | ||
/** | ||
* Check that the tested object is a DOM node property `value` equal | ||
@@ -1846,3 +1780,2 @@ * to an expected value. | ||
*/ | ||
function toHaveValue(_ref, expectedValue) { | ||
@@ -1873,6 +1806,6 @@ var actual = _ref.actual, | ||
toBeSelected: toBeSelected, | ||
toHaveId: toHaveId, | ||
toHaveAttrs: toHaveAttrs, | ||
toHaveCssClass: toHaveCssClass, | ||
toHaveHtml: toHaveHtml, | ||
toHaveId: toHaveId, | ||
toHaveProps: toHaveProps, | ||
@@ -1885,2 +1818,3 @@ toHaveStyle: toHaveStyle, | ||
// Create matchers and add it to the current jasmine environment. | ||
var jasmineMatchers = {}; | ||
@@ -1887,0 +1821,0 @@ forEach(keys(matchers), function(id) { |
{ | ||
"name": "jasmine-dom-spec", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "DOM Matchers and assertions for Jasmine framework", | ||
@@ -35,33 +35,32 @@ "main": "dist/jasmine-dom-spec.js", | ||
"devDependencies": { | ||
"@babel/core": "7.16.7", | ||
"@babel/preset-env": "7.16.7", | ||
"@rollup/plugin-babel": "5.3.0", | ||
"@rollup/plugin-commonjs": "21.0.1", | ||
"@rollup/plugin-node-resolve": "13.1.2", | ||
"@types/jasmine": "3.10.3", | ||
"@typescript-eslint/eslint-plugin": "5.9.0", | ||
"@typescript-eslint/parser": "5.9.0", | ||
"ansi-colors": "4.1.1", | ||
"del": "6.0.0", | ||
"dox": "0.9.0", | ||
"eslint": "8.6.0", | ||
"eslint-config-google": "0.14.0", | ||
"fancy-log": "1.3.3", | ||
"glob": "7.2.0", | ||
"gulp": "4.0.2", | ||
"@babel/core": "7.25.2", | ||
"@babel/preset-env": "7.25.4", | ||
"@rollup/plugin-babel": "6.0.4", | ||
"@rollup/plugin-commonjs": "26.0.1", | ||
"@rollup/plugin-node-resolve": "15.2.3", | ||
"@types/jasmine": "4.3.6", | ||
"@typescript-eslint/eslint-plugin": "8.5.0", | ||
"@typescript-eslint/parser": "8.5.0", | ||
"ansi-colors": "4.1.3", | ||
"dox": "1.0.0", | ||
"eslint": "8.57.0", | ||
"eslint-config-airbnb-base": "15.0.0", | ||
"eslint-plugin-import": "2.30.0", | ||
"fancy-log": "2.0.0", | ||
"glob": "11.0.0", | ||
"gulp": "5.0.0", | ||
"gulp-bump": "3.2.0", | ||
"gulp-eslint": "6.0.0", | ||
"gulp-git": "2.10.1", | ||
"gulp-git": "2.11.0", | ||
"gulp-rename": "2.0.0", | ||
"gulp-tag-version": "1.3.1", | ||
"handlebars": "4.7.7", | ||
"handlebars": "4.7.8", | ||
"jasmine-core": "3.10.1", | ||
"jquery": "1.12.4", | ||
"karma": "6.3.9", | ||
"karma-chrome-launcher": "3.1.0", | ||
"karma-firefox-launcher": "2.1.2", | ||
"karma-jasmine": "4.0.1", | ||
"karma": "6.4.4", | ||
"karma-chrome-launcher": "3.2.0", | ||
"karma-firefox-launcher": "2.1.3", | ||
"karma-jasmine": "4.0.2", | ||
"karma-jasmine-html-reporter": "1.7.0", | ||
"karma-phantomjs-launcher": "1.0.4", | ||
"karma-rollup-preprocessor": "7.0.7", | ||
"karma-rollup-preprocessor": "7.0.8", | ||
"karma-safari-launcher": "1.0.0", | ||
@@ -71,11 +70,11 @@ "karma-sauce-launcher": "4.3.6", | ||
"phantomjs-prebuilt": "2.1.16", | ||
"q": "1.5.1", | ||
"rollup": "2.63.0", | ||
"rollup-plugin-esformatter": "2.0.1", | ||
"rollup-plugin-license": "2.6.1", | ||
"rollup-plugin-strip-banner": "2.0.0", | ||
"touch": "3.1.0", | ||
"typescript": "4.5.4" | ||
"rimraf": "6.0.1", | ||
"rollup": "4.21.2", | ||
"rollup-plugin-esformatter": "3.1.0", | ||
"rollup-plugin-license": "3.5.2", | ||
"rollup-plugin-strip-banner": "3.1.0", | ||
"touch": "3.1.1", | ||
"typescript": "5.6.2" | ||
}, | ||
"dependencies": {} | ||
} |
@@ -248,3 +248,3 @@ jasmine-dom-spec | ||
| `attrName` | `String,Object` | Attribute name (or map of attributes). | | ||
| `attrValue` | `String,RegExp,jasmine.Any,jasmine.Anything` | Attribute value or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
| `attrValue` | `String,RegExp,[object Object],[object Object]` | Attribute value or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
@@ -282,3 +282,3 @@ #### Message | ||
|------|------|-------------| | ||
| `expected` | `Array.<string>,String` | The expected class name. | | ||
| `expected` | `Array<string>,String` | The expected class name. | | ||
@@ -321,3 +321,3 @@ #### Message | ||
|------|------|-------------| | ||
| `html` | `String,Number,Boolean,RegExp,jasmine.Any,jasmine.Anything` | The expected html or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
| `html` | `String,Number,Boolean,RegExp,[object Object],[object Object]` | The expected html or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
@@ -353,3 +353,3 @@ #### Message | ||
|------|------|-------------| | ||
| `id` | `String,RegExp,jasmine.Any,jasmine.Anything` | The expected id or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
| `id` | `String,RegExp,[object Object],[object Object]` | The expected id or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
@@ -386,3 +386,3 @@ #### Message | ||
| `propName` | `String,Object` | Property name (or object of properties). | | ||
| `propValue` | `*` | Property value. | | ||
| `propValue` | `[object Object]` | Property value. | | ||
@@ -424,3 +424,3 @@ #### Message | ||
| `styleName` | `String,Object` | Style name or object of styles. | | ||
| `styleValue` | `String,RegExp,jasmine.Any,jasmine.Anything` | Style value or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
| `styleValue` | `String,RegExp,[object Object],[object Object]` | Style value or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
@@ -459,3 +459,3 @@ #### Message | ||
|------|------|-------------| | ||
| `tagName` | `String,RegExp,jasmine.Any,jasmine.Anything` | The expected tag name or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
| `tagName` | `String,RegExp,[object Object],[object Object]` | The expected tag name or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
@@ -492,3 +492,3 @@ #### Message | ||
|------|------|-------------| | ||
| `text` | `String,Number,Boolean,RegExp,jasmine.Any,jasmine.Anything` | The expected text or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
| `text` | `String,Number,Boolean,RegExp,[object Object],[object Object]` | The expected text or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
@@ -526,3 +526,3 @@ #### Message | ||
|------|------|-------------| | ||
| `expectedValue` | `String,RegExp,jasmine.Any,jasmine.Anything` | The expected value or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
| `expectedValue` | `String,RegExp,[object Object],[object Object]` | The expected value or a jasmine matcher (i.e `jasmine.any(<Type>)`). | | ||
@@ -529,0 +529,0 @@ #### Message |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
75609
41
1727
0