Skip to content

Commit 92519aa

Browse files
committed
Added regex to check for important flag
1 parent e93d52b commit 92519aa

File tree

1 file changed

+13
-6
lines changed
  • exercises/07-Very-Specific-Rules

1 file changed

+13
-6
lines changed

exercises/07-Very-Specific-Rules/tests.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,24 @@ describe("All the styles should be applied", ()=>{
1111
const title = document.querySelector('title')
1212
const link = document.querySelector('link')
1313

14-
test("The ul li color has to be red", ()=>{
14+
test("The ul li color has to be red using !important", ()=>{
1515
document.querySelector(
1616
"head"
1717
).innerHTML = `<style>${css.toString()}</style>`;
18+
1819
let cssArray = document.styleSheets[0].cssRules;
19-
let orangeHoverSelector = "";
20+
let color = ""
21+
2022
for (let i = 0; i < cssArray.length; i++) {
2123
if (cssArray[i].selectorText === "ul li" || cssArray[i].selectorText === "ul > li") {
22-
orangeHoverSelector = cssArray[i].style["color"];
24+
color = cssArray[i].cssText;
2325
}
2426
}
25-
expect(orangeHoverSelector).toBe("red");
27+
let reg = new RegExp(/\s*color:\s*red\s*!important\s*;\s*/gm)
28+
29+
expect(reg.test(color)).toBeTruthy();
2630
});
31+
2732
test("The ul second element background should be green", ()=>{
2833
document.querySelector(
2934
"head"
@@ -39,6 +44,7 @@ describe("All the styles should be applied", ()=>{
3944

4045
} expect(orangeHoverSelector).toBe("green");
4146
})
47+
4248
test("The odd rows of the table should have yellow background", ()=>{
4349
document.querySelector(
4450
"head"
@@ -63,8 +69,8 @@ describe("All the styles should be applied", ()=>{
6369
let cssArray = document.styleSheets[0].cssRules[4].selectorText;
6470
expect(cssArray).toBe("ul li,\nol li");
6571
expect(cssBody).toBe("body");
66-
}
67-
)
72+
})
73+
6874
test("You should not change the existing head tag elements", ()=>{
6975
let head = document.querySelector('head')
7076
expect(head).toBeTruthy()
@@ -76,4 +82,5 @@ describe("All the styles should be applied", ()=>{
7682

7783
expect(title).toBeTruthy()
7884
})
85+
7986
});

0 commit comments

Comments
 (0)