Skip to content

Commit

Permalink
feat(setOptions): add spec "setOptions: it should override the duplic…
Browse files Browse the repository at this point in the history
…ate key"
  • Loading branch information
59naga committed Apr 18, 2016
1 parent 57b999f commit 84e7504
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// no dependencies
const TYPE = Symbol();
const VALUE = Symbol();
const OPTS = Symbol();
const META = Symbol();
const TYPE = Symbol('type');
const VALUE = Symbol('value');
const OPTS = Symbol('options');
const META = Symbol('meta');

// @class Token
export default class Token {
Expand Down Expand Up @@ -81,6 +81,16 @@ export default class Token {
return this;
}

/**
* @method setOptions
* @param {object} options - override the options
* @returns {this} this
*/
setOptions(options) {
this[OPTS] = { ...this[OPTS], ...options };
return this;
}

/**
* @method setMeta
* @param {string} key - a meta key
Expand Down
9 changes: 9 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ test('clone is should be changed meta-information only', (t) => {
t.true(clonedToken.meta.transformer === 'johndue');
});

test('setOptions: it should override the duplicate key', (t) => {
const token = new Token('text', 'foo', { pitch: 1 });
token.setOptions({ volume: 0.5, pitch: 2 });

t.true(Object.keys(token.options).length === 2);
t.true(token.options.volume === 0.5);
t.true(token.options.pitch === 2);
});

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: {} }));
Expand Down

0 comments on commit 84e7504

Please sign in to comment.