Skip to content

Commit

Permalink
fix: don't throw error for toValue on value-less kvp
Browse files Browse the repository at this point in the history
  • Loading branch information
kylef committed Jun 11, 2020
1 parent f197ca5 commit c0cb4b0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Minim Changelog

## Master

### Bug Fixes

- Prevent throwing an error when calling `toValue()` on an element with a key
value pair which does not have a value.

## 0.23.7 (2020-04-27)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion lib/primitives/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class Element {
if (this.content instanceof KeyValuePair) {
return {
key: this.content.key.toValue(),
value: this.content.value.toValue(),
value: this.content.value ? this.content.value.toValue() : undefined,
};
}

Expand Down
25 changes: 25 additions & 0 deletions test/primitives/Element-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,31 @@ describe('Element', () => {
value: 'doe',
});
});

it('returns KeyValuePair without value', () => {
const element = new minim.Element(
new KeyValuePair(
new minim.Element('name')
)
);

const value = element.toValue();
expect(value.key).to.equal('name');
expect(value.value).to.be.undefined;
});

it('returns KeyValuePair with empty value', () => {
const element = new minim.Element(
new KeyValuePair(
new minim.Element('name'),
new minim.Element()
)
);

const value = element.toValue();
expect(value.key).to.equal('name');
expect(value.value).to.be.undefined;
});
});

describe('freezing an element', () => {
Expand Down

0 comments on commit c0cb4b0

Please sign in to comment.