Socket
Socket
Sign inDemoInstall

jasmine-dom-spec

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jasmine-dom-spec - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

2

bower.json
{
"name": "jasmine-dom-spec",
"version": "0.8.0",
"version": "0.9.0",
"authors": [

@@ -5,0 +5,0 @@ "Mickael Jeanroy"

@@ -27,5 +27,7 @@ /**

type Primitive = string | number | boolean;
type NodeId = string | RegExp | jasmine.Any;
type NodeSelectedIndex = number | jasmine.Any;
type NodeTagName = string | RegExp | jasmine.Any;
type NodeContent = string | number | boolean | RegExp | jasmine.Any;
type NodeContent = Primitive | Array<Primitive> | RegExp | jasmine.Any;
type NodeInputValue = string | RegExp | jasmine.Any;

@@ -58,2 +60,3 @@ type NodeClassName = string | RegExp | jasmine.Any;

toBeIndeterminate(): boolean;
toBeReadOnly(): boolean;
toBeRequired(): boolean;

@@ -63,2 +66,3 @@ toBeSelected(): boolean;

toHaveAttrs(attrs: NodeAttributeDictionary): boolean;
toHaveComputedStyle(name: string, value: NodeStyle): boolean;
toHaveCssClass(classNames: NodeClassName | NodeClassName[]): boolean;

@@ -69,2 +73,3 @@ toHaveHtml(text: NodeContent): boolean;

toHaveProps(props: NodePropsDictionary): boolean;
toHaveSelectedIndex(props: NodeSelectedIndex): boolean;
toHaveStyle(name: string, value: NodeStyle): boolean;

@@ -71,0 +76,0 @@ toHaveStyle(styles: NodeStyleDictionary): boolean;

@@ -1014,2 +1014,29 @@ /**

/**
* Check that the tested object is a DOM node with a property `readOnly` equal
* to `true`.
*
* @message Expect [actual] [NOT] to be read-only
* @example
* const actual = document.createElement('input');
* actual.readOnly = true;
* expect(actual).toBeReadOnly();
*
* @param {Object} ctx Test context.
* @return {Object} Test result.
* @since 0.9.0
*/
function toBeReadOnly(_ref) {
var actual = _ref.actual,
pp = _ref.pp;
var node = toDomElement(actual, pp);
ensureHasIn(node, 'readOnly', 'Cannot run `toBeReadOnly` matcher on a DOM node without `readOnly` property');
return {
pass: node.readOnly === true,
message: function message() {
return "Expect " + pp(actual) + " [NOT] to be read-only";
}
};
}
/**
* Check that the tested object is a DOM node with a property `required` equal

@@ -1201,2 +1228,78 @@ * to `true`.

/**
* Turn a string, formatted as dash-case to a string formatted as
* camelCase.
*
* @param {string} value The dash-case string.
* @return {string} The camelCase string.
*/
function dashToCamel(value) {
if (!value) {
return value;
}
var result = '';
var turnToUpper = false;
for (var i = 0, size = value.length; i < size; ++i) {
var c = value.charAt(i);
if (c === '-') {
turnToUpper = true;
} else {
result += turnToUpper ? c.toUpperCase() : c;
turnToUpper = false;
}
}
return result;
}
var _getComputedStyle = getComputedStyle ? function(el) {
return getComputedStyle(el, null);
} : function(el) {
return el.currentStyle;
};
/**
* Check that the tested object has expected computed style value (the css style property
* name can dash-cased, such as `font-size`, or camel cased, such as `fontSize`).
*
* @message Expect [actual] [NOT] to have computed styles [expected]
* @example
* const actual = document.createElement('input');
* actual.required = true;
* actual.checked = false;
* expect(actual).toHaveComputedStyle('display', 'none');
* expect(actual).toHaveComputedStyle('font-size', '10px');
* expect(actual).toHaveComputedStyle('font-size', /10/);
* expect(actual).toHaveComputedStyle({fontSize: '10px', display: 'none'});
* expect(actual).toHaveComputedStyle({fontSize: /10/, display: 'none'});
* expect(actual).toHaveComputedStyle({fontSize: jasmine.anything()});
*
* @param {Object} ctx Test context.
* @param {String|Object} styleName Style name or object of styles.
* @param {String|RegExp|jasmine.Any|jasmine.Anything} styleValue Style value or a jasmine matcher (i.e `jasmine.any(<Type>)`).
* @return {Object} Test result.
* @since 0.9.0
*/
function toHaveComputedStyle(_ref, styleName, styleValue) {
var _ref2;
var actual = _ref.actual,
equals = _ref.equals,
pp = _ref.pp;
var node = toDomElement(actual, pp);
var expected = isObject(styleName) ? styleName : (_ref2 = {}, _ref2[styleName] = styleValue, _ref2);
var props = keys(expected);
var computedStyle = _getComputedStyle(node);
var ok = every(props, function(name) {
var camelCaseName = dashToCamel(name);
var actualValue = computedStyle[camelCaseName];
var expectedValue = expected[name];
return matchOrEquals(actualValue, expectedValue, equals);
});
return {
pass: ok,
message: function message() {
return "Expect " + pp(actual) + " [NOT] to have computed styles " + pp(expected);
}
};
}
/**
* Apply a predicate function on all the values of an array (also supports array-like

@@ -1501,24 +1604,32 @@ * objects) and returns an array without elements that satisfied the predicate.

/**
* Turn a string, formatted as dash-case to a string formatted as
* camelCase.
* Check that the tested object is a DOM node with a `selectedIndex` property with an expected value.
*
* @param {string} value The dash-case string.
* @return {string} The camelCase string.
* @message Expect [actual] [NOT] to have id [id] but was [id]
* @example
* const actual = document.createElement('select');
* actual.appendChild(document.createElement('option'));
* actual.appendChild(document.createElement('option'));
* actual.selectedIndex = 1;
* expect(actual).toHaveSelectedIndex(1);
* expect(actual).not.toHaveSelectedIndex(0);
*
* @param {Object} ctx Test context.
* @param {Number|jasmine.Any|jasmine.Anything} selectedIndex The expected selectedIndex or a jasmine matcher (i.e `jasmine.any(<Type>)`).
* @return {Object} Test result.
* @since 0.9.0
*/
function dashToCamel(value) {
if (!value) {
return value;
}
var result = '';
var turnToUpper = false;
for (var i = 0, size = value.length; i < size; ++i) {
var c = value.charAt(i);
if (c === '-') {
turnToUpper = true;
} else {
result += turnToUpper ? c.toUpperCase() : c;
turnToUpper = false;
function toHaveSelectedIndex(_ref, selectedIndex) {
var actual = _ref.actual,
equals = _ref.equals,
pp = _ref.pp;
var node = toDomElement(actual, pp);
ensureHasIn(node, 'selectedIndex', 'Cannot run `toHaveSelectedIndex` matcher on a DOM node without `selectedIndex` property');
var actualSelectedIndex = node.selectedIndex;
var pass = matchOrEquals(actualSelectedIndex, selectedIndex, equals);
return {
pass: pass,
message: function message() {
return "Expect " + pp(actual) + " [NOT] to have selectedIndex " + pp(selectedIndex) + " but was " + pp(actualSelectedIndex);
}
}
return result;
};
}

@@ -1631,3 +1742,3 @@

* @param {Object} ctx Test context.
* @param {String|Number|Boolean|RegExp|jasmine.Any|jasmine.Anything} text The expected text or a jasmine matcher (i.e `jasmine.any(<Type>)`).
* @param {String|Number|Boolean|RegExp|Array<String|Number|Boolean>|jasmine.Any|jasmine.Anything} text The expected text or a jasmine matcher (i.e `jasmine.any(<Type>)`).
* @return {Object} Test result.

@@ -1643,3 +1754,3 @@ * @since 0.1.0

var actualText = 'textContent' in node ? node.textContent : node.innerText;
var expectedText = isPrimitive(text) ? text.toString() : text;
var expectedText = toString(text);
var ok = matchOrEquals(normalizeTextContent(actualText), normalizeTextContent(expectedText), equals);

@@ -1655,2 +1766,21 @@ return {

/**
* Transform `text` to string if possible:
* - Serialize primitive types (number, boolean, string) to string.
* - Join array elements with the line separator character.
* - Otherwise, returns `text`.
*
* @param {String|Number|Boolean|RegExp|Array<String|Number|Boolean>|jasmine.Any|jasmine.Anything} text The expected text or a jasmine matcher (i.e `jasmine.any(<Type>)`).
* @return {*|string} String value, or `text`.
*/
function toString(text) {
if (isPrimitive(text)) {
return text.toString();
}
if (isArray(text)) {
return text.join('\n');
}
return text;
}
/**
* Normalize text content by trimming it if it is a string.

@@ -1706,5 +1836,7 @@ *

toBeIndeterminate: toBeIndeterminate,
toBeReadOnly: toBeReadOnly,
toBeRequired: toBeRequired,
toBeSelected: toBeSelected,
toHaveAttrs: toHaveAttrs,
toHaveComputedStyle: toHaveComputedStyle,
toHaveCssClass: toHaveCssClass,

@@ -1714,2 +1846,3 @@ toHaveHtml: toHaveHtml,

toHaveProps: toHaveProps,
toHaveSelectedIndex: toHaveSelectedIndex,
toHaveStyle: toHaveStyle,

@@ -1716,0 +1849,0 @@ toHaveTagName: toHaveTagName,

{
"name": "jasmine-dom-spec",
"version": "0.8.0",
"version": "0.9.0",
"description": "DOM Matchers and assertions for Jasmine framework",

@@ -5,0 +5,0 @@ "main": "dist/jasmine-dom-spec.js",

@@ -181,2 +181,29 @@ jasmine-dom-spec

### toBeReadOnly
Check that the tested object is a DOM node with a property `readOnly` equal
to `true`.
#### Since
0.9.0
#### Parameters
*No parameters*
#### Message
`Expect [actual] [NOT] to be read-only`
#### Example:
```javascript
it('should pass', () => {
const actual = document.createElement('input');
actual.readOnly = true;
expect(actual).toBeReadOnly();
});
```
### toBeRequired

@@ -270,2 +297,38 @@

### toHaveComputedStyle
Check that the tested object has expected computed style value (the css style property
name can dash-cased, such as `font-size`, or camel cased, such as `fontSize`).
#### Since
0.9.0
#### Parameters
| Name | Type | Description |
|------|------|-------------|
| `styleName` | `String,Object` | Style name or object of styles. |
| `styleValue` | `String,RegExp,[object Object],[object Object]` | Style value or a jasmine matcher (i.e `jasmine.any(<Type>)`). |
#### Message
`Expect [actual] [NOT] to have computed styles [expected]`
#### Example:
```javascript
it('should pass', () => {
const actual = document.createElement('input');
actual.required = true;
actual.checked = false;
expect(actual).toHaveComputedStyle('display', 'none');
expect(actual).toHaveComputedStyle('font-size', '10px');
expect(actual).toHaveComputedStyle('font-size', /10/);
expect(actual).toHaveComputedStyle({fontSize: '10px', display: 'none'});
expect(actual).toHaveComputedStyle({fontSize: /10/, display: 'none'});
expect(actual).toHaveComputedStyle({fontSize: jasmine.anything()});
});
```
### toHaveCssClass

@@ -407,2 +470,33 @@

### toHaveSelectedIndex
Check that the tested object is a DOM node with a `selectedIndex` property with an expected value.
#### Since
0.9.0
#### Parameters
| Name | Type | Description |
|------|------|-------------|
| `selectedIndex` | `Number,[object Object],[object Object]` | The expected selectedIndex or a jasmine matcher (i.e `jasmine.any(<Type>)`). |
#### Message
`Expect [actual] [NOT] to have id [id] but was [id]`
#### Example:
```javascript
it('should pass', () => {
const actual = document.createElement('select');
actual.appendChild(document.createElement('option'));
actual.appendChild(document.createElement('option'));
actual.selectedIndex = 1;
expect(actual).toHaveSelectedIndex(1);
expect(actual).not.toHaveSelectedIndex(0);
});
```
### toHaveStyle

@@ -488,3 +582,3 @@

|------|------|-------------|
| `text` | `String,Number,Boolean,RegExp,[object Object],[object Object]` | The expected text or a jasmine matcher (i.e `jasmine.any(<Type>)`). |
| `text` | `String,Number,Boolean,RegExp,Array<String|Number|Boolean>,[object Object],[object Object]` | The expected text or a jasmine matcher (i.e `jasmine.any(<Type>)`). |

@@ -491,0 +585,0 @@ #### Message

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