-
-
Notifications
You must be signed in to change notification settings - Fork 25
Implement universal selector handling in getStyle #561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
0760191
0284bd9
17d935e
02d59cd
d7fd709
044a0e9
1e1aab9
efcdc21
f55e3ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,15 +4,22 @@ import React from "react"; | |
| import ReactDOM from "react-dom/client"; | ||
|
|
||
| import cssTestValues from "./__fixtures__/curriculum-helper-css"; | ||
|
|
||
| import htmlTestValues from "./__fixtures__/curriculum-helpers-html"; | ||
| import jsTestValues from "./__fixtures__/curriculum-helpers-javascript"; | ||
| import whiteSpaceTestValues from "./__fixtures__/curriculum-helpers-remove-white-space"; | ||
|
|
||
| import * as helper from "./../helpers/lib/index"; | ||
|
|
||
| const { stringWithWhiteSpaceChars, stringWithWhiteSpaceCharsRemoved } = | ||
| whiteSpaceTestValues; | ||
|
|
||
| const { cssFullExample, cssCodeWithCommentsRemoved } = cssTestValues; | ||
| const { | ||
| cssFullExample, | ||
| cssCodeWithCommentsRemoved, | ||
| cssWithUniversal, | ||
| cssWithoutUniversal, | ||
| } = cssTestValues; | ||
|
||
|
|
||
| const { htmlFullExample, htmlCodeWithCommentsRemoved } = htmlTestValues; | ||
|
|
||
|
|
@@ -862,3 +869,75 @@ describe("permutateRegex", () => { | |
| expect(regex.test(`'b" === a`)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("CSSHelp – universal selector handling", () => { | ||
| afterEach(() => { | ||
| document.head.innerHTML = ""; | ||
| }); | ||
|
|
||
| it("want universal selector, universal selector in css", () => { | ||
| const styleEl = document.createElement("style"); | ||
| styleEl.textContent = ` | ||
| span[class~="one"] *:first-of-type { | ||
| border-color: #d61; | ||
| } | ||
| `; | ||
|
||
| document.head.appendChild(styleEl); | ||
|
|
||
| const cssHelp = new helper.CSSHelp(document); | ||
|
|
||
| const style = cssHelp.getStyle('span[class~="one"] *:first-of-type'); | ||
|
|
||
| expect(style).not.toBeNull(); | ||
| expect(style?.getPropVal("border-color")).toBe("#d61"); | ||
| }); | ||
|
|
||
| it("want universal selector, universal selector not in css", () => { | ||
| const styleEl = document.createElement("style"); | ||
| styleEl.textContent = ` | ||
| span[class~="one"] > p:first-of-type { | ||
| color: red; | ||
| } | ||
| `; | ||
|
||
| document.head.appendChild(styleEl); | ||
|
|
||
| const cssHelp = new helper.CSSHelp(document); | ||
|
|
||
| const style = cssHelp.getStyle('span[class~="one"] *:first-of-type'); | ||
|
|
||
| expect(style).toBeNull(); | ||
| }); | ||
|
|
||
| it("don't want universal selector, universal selector in css", () => { | ||
| const styleEl = document.createElement("style"); | ||
| styleEl.textContent = ` | ||
| span[class~="one"] *:first-of-type { | ||
| border-color: #d61; | ||
| } | ||
| `; | ||
| document.head.appendChild(styleEl); | ||
|
|
||
| const cssHelp = new helper.CSSHelp(document); | ||
|
|
||
| const style = cssHelp.getStyle('span[class~="one"] > p:first-of-type'); | ||
|
|
||
| expect(style).toBeNull(); | ||
| }); | ||
|
|
||
| it("don't want universal selector, universal selector not in css", () => { | ||
| const styleEl = document.createElement("style"); | ||
| styleEl.textContent = ` | ||
| span[class~="one"] > p:first-of-type { | ||
| color: red; | ||
| } | ||
| `; | ||
| document.head.appendChild(styleEl); | ||
|
|
||
| const cssHelp = new helper.CSSHelp(document); | ||
|
|
||
| const style = cssHelp.getStyle('span[class~="one"] > p:first-of-type'); | ||
|
|
||
| expect(style).not.toBeNull(); | ||
| expect(style?.getPropVal("color")).toBe("red"); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the changes to this file are only some empty lines added, please revert