Skip to content

Commit

Permalink
feat(toJSON): add spec "should expose the property at the JSON.string…
Browse files Browse the repository at this point in the history
…ify"
  • Loading branch information
59naga committed Apr 16, 2016
1 parent bd7570f commit fc4b418
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export default class Token {
get meta() {
return this[META];
}
toJSON() {
return {
type: this.type,
value: this.value,
options: this.options,
meta: this.meta,
};
}

/**
* @method clone
Expand Down
5 changes: 5 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ test('clone is should be changed meta-information only', (t) => {
t.true(token.meta.transformer === undefined);
t.true(clonedToken.meta.transformer === 'johndue');
});

test('should expose the property at the JSON.stringify', (t) => {
const string = JSON.stringify(new Token('text', 'foo'));
t.true(string === JSON.stringify({ type: 'text', value: 'foo', options: {}, meta: {} }));
});

0 comments on commit fc4b418

Please sign in to comment.