Index: test/elemHide.js |
=================================================================== |
--- a/test/elemHide.js |
+++ b/test/elemHide.js |
@@ -42,30 +42,42 @@ |
callback(); |
}; |
function normalizeSelectors(selectors) |
{ |
// getSelectorsForDomain is currently allowed to return duplicate selectors |
// for performance reasons, so we need to remove duplicates here. |
- return selectors.sort().filter((selector, index, sortedSelectors) => |
+ return selectors.slice().sort().filter((selector, index, sortedSelectors) => |
Manish Jethani
2018/09/20 12:27:24
Somewhat unrelated, but we should make a copy and
Jon Sonesen
2018/09/20 20:10:20
Acknowledged.
Just curious, since slice returns a
Manish Jethani
2018/09/21 10:53:05
The selectors themselves are immutable string obje
Jon Sonesen
2018/09/23 18:01:59
Yeah I figured since it is test code the importanc
|
{ |
return index == 0 || selector != sortedSelectors[index - 1]; |
}); |
} |
function testResult(test, domain, expectedSelectors, specificOnly) |
{ |
let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors); |
test.deepEqual( |
normalizeSelectors(ElemHide.getSelectorsForDomain(domain, specificOnly)), |
normalizedExpectedSelectors |
); |
+ |
+ let {code, selectors} = |
+ ElemHide.generateStyleSheetForDomain(domain, specificOnly); |
+ |
+ test.deepEqual(normalizeSelectors(selectors), normalizedExpectedSelectors); |
+ |
+ // Make sure each expected selector is in the actual CSS code. |
+ for (let selector of normalizedExpectedSelectors) |
+ { |
+ test.ok(code.includes(selector + ", ") || |
+ code.includes(selector + " {display: none !important;}\n")); |
+ } |
Jon Sonesen
2018/09/20 20:10:20
I am sort of confused by the set literal `{code, s
Manish Jethani
2018/09/21 10:53:05
This is called a destructuring assignment [1]
[1]
Jon Sonesen
2018/09/23 18:01:59
I do think the convention is helpful tbh so I was
|
} |
exports.testGetSelectorsForDomain = function(test) |
{ |
let addFilter = filterText => ElemHide.add(Filter.fromText(filterText)); |
let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText)); |
let addException = |
filterText => ElemHideExceptions.add(Filter.fromText(filterText)); |