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

dom-testing-library

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-testing-library - npm Package Compare versions

Comparing version 1.6.2 to 1.7.0

dist/get-node-text.js

12

dist/index.js

@@ -56,2 +56,14 @@ 'use strict';

var _getNodeText = require('./get-node-text');
Object.keys(_getNodeText).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _getNodeText[key];
}
});
});
var _events = require('./events');

@@ -58,0 +70,0 @@

7

dist/matches.js

@@ -10,8 +10,9 @@ 'use strict';

}
var normalizedText = textToMatch.toLowerCase().trim().replace(/\s+/g, ' ');
if (typeof matcher === 'string') {
return textToMatch.toLowerCase().includes(matcher.toLowerCase());
return normalizedText.includes(matcher.toLowerCase());
} else if (typeof matcher === 'function') {
return matcher(textToMatch, node);
return matcher(normalizedText, node);
} else {
return matcher.test(textToMatch);
return matcher.test(normalizedText);
}

@@ -18,0 +19,0 @@ }

@@ -14,2 +14,4 @@ 'use strict';

var _getNodeText = require('./get-node-text');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -67,3 +69,3 @@

return Array.from(container.querySelectorAll(selector)).find(function (node) {
return (0, _matches.matches)(getText(node), node, text);
return (0, _matches.matches)((0, _getNodeText.getNodeText)(node), node, text);
}) || null;

@@ -83,12 +85,2 @@ }

// this is just a utility and not an exposed query.
// There are no plans to expose this.
function getText(node) {
return Array.from(node.childNodes).filter(function (child) {
return child.nodeType === Node.TEXT_NODE && Boolean(child.textContent);
}).map(function (c) {
return c.textContent;
}).join(' ').trim().replace(/\s+/g, ' ');
}
// getters

@@ -95,0 +87,0 @@ // the reason we're not dynamically generating these functions that look so similar:

{
"name": "dom-testing-library",
"version": "1.6.2",
"version": "1.7.0",
"description": "Simple and complete DOM testing utilities that encourage good testing practices.",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -398,2 +398,21 @@ <div align="center">

#### `getNodeText(node: HTMLElement)`
Returns the complete text content of a html element, removing any extra
whitespace. The intention is to treat text in nodes exactly as how it is
perceived by users in a browser, where any extra whitespace within words in the
html code is not meaningful when the text is rendered.
```javascript
// <div>
// Hello
// World !
// </div>
const text = getNodeText(container.querySelector('div')) // "Hello World !"
```
This function is also used internally when querying nodes by their text content.
This enables functions like `getByText` and `queryByText` to work as expected,
finding elements in the DOM similarly to how users would do.
## Custom Jest Matchers

@@ -400,0 +419,0 @@

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