Skip to content

Commit

Permalink
Merge pull request #243 from codr/patch-1
Browse files Browse the repository at this point in the history
Add support for multiple matching blocks
  • Loading branch information
jgerigmeyer authored Nov 9, 2022
2 parents 9d4823d + bd1d59f commit 3ecec59
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
path (or string), 3) optional Sass options
- BREAKING: Require `sass` as a peer-dependency, removing True `sass` option
- BREAKING: Drop support for node < 14.15.0
- FEATURE: `contains()` checks multiple block with matching selectors.
[#243](https://github.com/oddbird/true/pull/243)
- INTERNAL: Use both Jest and Mocha for internal testing
- INTERNAL: Update dependencies

Expand Down
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ const contains = function (output: string, expected: string) {
const expectedBlocks = createSelectorsRulesPairs(expected);

const results = expectedBlocks.map((block) => {
const outputBlock = outputBlocks.find(
const matchingOutputBlocks = outputBlocks.filter(
(element) => element.selector === block.selector,
);
if (outputBlock) {
if (matchingOutputBlocks.length) {
// Turns a css string into an array of property-value pairs.
const expectedProperties = block.output
.split(';')
Expand All @@ -231,7 +231,9 @@ const contains = function (output: string, expected: string) {

// This is the assertion itself!
return expectedProperties.every((property) =>
outputBlock.output.includes(property),
matchingOutputBlocks.some((outputBlock) =>
outputBlock.output.includes(property),
),
);
}
return false;
Expand Down
29 changes: 25 additions & 4 deletions test/css/test.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions test/scss/assert/_output.scss
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,25 @@
}
}
}

@include it('Can assert with multiple matching selector') {
@include assert {
@include output {
.selector {
width: 10px;
}
.selector {
min-height: 5px;
max-height: 20px;
}
}

@include contains {
.selector {
width: 10px;
min-height: 5px;
}
}
}
}
}

0 comments on commit 3ecec59

Please sign in to comment.