Commit 4d6bb3d7 authored by David Sveningsson's avatar David Sveningsson

fix: disable `void-style` when using `toHTMLValidate` matcher

parent 0ba1d06d
Pipeline #122661438 passed with stages
in 10 minutes and 22 seconds
......@@ -33,6 +33,12 @@ const elem = document.createElement("div");
expect(elem).toHTMLValidate();
```
<div class="alert alert-info">
<i class="fa fa-info-circle" aria-hidden="true"></i>
<strong>Note</strong>
<p>The {@link void-style} rule is disabled by default since jsdom normalizes the style. It can be enabled by passing a custom configuration reenabling it.</p>
</div>
If needed a custom configuration can be passed:
```js
......
......@@ -246,6 +246,11 @@ describe("toHTMLValidate()", () => {
});
});
it("should ignore void-style by default", () => {
expect.assertions(1);
expect("<hr><hr/>").toHTMLValidate();
});
it("should support jsdom", () => {
/* eslint-disable-next-line @typescript-eslint/ban-ts-ignore */
// @ts-ignore DOM library not available
......
/* eslint-disable @typescript-eslint/no-namespace, @typescript-eslint/ban-ts-ignore, prefer-template, sonarjs/no-duplicate-string */
import diff from "jest-diff";
import deepmerge from "deepmerge";
import { TokenType } from "./lexer";
import { Message, Report, Result } from "./reporter";
import { ConfigData } from "./config";
......@@ -144,7 +145,7 @@ function toHTMLValidate(
this: jest.MatcherUtils,
// @ts-ignore DOM library not available
actual: string | HTMLElement,
config?: ConfigData,
userConfig?: ConfigData,
filename?: string
): jest.CustomMatcherResult {
// @ts-ignore DOM library not available
......@@ -152,6 +153,15 @@ function toHTMLValidate(
actual = actual.outerHTML;
}
const defaultConfig = {
rules: {
/* jsdom normalizes style so disabling rule when using this matcher or it
* gets quite noisy when configured with self-closing */
"void-style": "off",
},
};
const config = deepmerge(defaultConfig, userConfig || {});
const actualFilename = filename || this.testPath;
const htmlvalidate = new HtmlValidate();
const report = htmlvalidate.validateString(actual, actualFilename, config);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment