Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@testing-library/jest-dom

Package Overview
Dependencies
Maintainers
12
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@testing-library/jest-dom - npm Package Compare versions

Comparing version 5.2.0 to 5.3.0

37

dist/to-have-class.js

@@ -12,2 +12,22 @@ "use strict";

function getExpectedClassNamesAndOptions(params) {
const lastParam = params.pop();
let expectedClassNames, options;
if (typeof lastParam === 'object') {
expectedClassNames = params;
options = lastParam;
} else {
expectedClassNames = params.concat(lastParam);
options = {
exact: false
};
}
return {
expectedClassNames,
options
};
}
function splitClassNames(str) {

@@ -25,6 +45,21 @@ if (!str) {

function toHaveClass(htmlElement, ...expectedClassNames) {
function toHaveClass(htmlElement, ...params) {
(0, _utils.checkHtmlElement)(htmlElement, toHaveClass, this);
const {
expectedClassNames,
options
} = getExpectedClassNamesAndOptions(params);
const received = splitClassNames(htmlElement.getAttribute('class'));
const expected = expectedClassNames.reduce((acc, className) => acc.concat(splitClassNames(className)), []);
if (options.exact) {
return {
pass: isSubset(expected, received) && expected.length === received.length,
message: () => {
const to = this.isNot ? 'not to' : 'to';
return (0, _utils.getMessage)(`Expected the element ${to} have EXACTLY defined classes`, expected.join(' '), 'Received', received.join(' '));
}
};
}
return expected.length > 0 ? {

@@ -31,0 +66,0 @@ pass: isSubset(expected, received),

2

package.json
{
"name": "@testing-library/jest-dom",
"version": "5.2.0",
"version": "5.3.0",
"description": "Custom jest matchers to test the state of the DOM",

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

@@ -49,2 +49,3 @@ <div align="center">

- [Installation](#installation)

@@ -502,3 +503,3 @@ - [Usage](#usage)

```typescript
toHaveClass(...classNames: string[])
toHaveClass(...classNames: string[], options?: {exact: boolean})
```

@@ -530,2 +531,5 @@

expect(deleteButton).toHaveClass('btn-danger extra btn', {exact: true}) // to check if the element has EXACTLY a set of classes
expect(deleteButton).not.toHaveClass('btn-danger extra', {exact: true}) // if it has more than expected it is going to fail
expect(noClasses).not.toHaveClass()

@@ -946,2 +950,3 @@ ```

<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

@@ -948,0 +953,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