Skip to content

Commit

Permalink
feat: trim rdtc result
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Feb 8, 2019
1 parent 2adef8f commit 733c0ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/subroutineAliasPreset.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default {
return readSubroutine(subject, ['attribute'].concat(values), bindle);
},
rdtc: (subject, values, bindle) => {
return readSubroutine(removeSubroutine(subject, ['*', '{0,}'], bindle), ['property', 'textContent'], bindle);
return readSubroutine(removeSubroutine(subject, ['*', '{0,}'], bindle), ['property', 'textContent'], bindle).trim();
},
rih: (subject, values, bindle) => {
return readSubroutine(subject, ['property', 'innerHTML'], bindle);
Expand Down
17 changes: 17 additions & 0 deletions test/surgeon/aliases.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ test('rdtc: reads direct textNode textContent property', (t): void => {
t.deepEqual(x(query, subject), 'bar');
});

test('rdtc: trims value', (t): void => {
const x = surgeon({
subroutines: subroutineAliasPreset
});

const subject = `
<div class="foo">
bar
<div>baz</div>
</div>
`;

const query = 'so .foo | rdtc';
t.deepEqual(x(query, subject), 'bar');
});
test('rtc: reads textContent property', (t): void => {
const x = surgeon({
subroutines: subroutineAliasPreset
Expand Down

0 comments on commit 733c0ad

Please sign in to comment.