From 84e7504af0f0f620697b35d3b44dd380ea8e3a3e Mon Sep 17 00:00:00 2001 From: 59naga Date: Mon, 18 Apr 2016 10:25:26 +0900 Subject: [PATCH] feat(setOptions): add spec "setOptions: it should override the duplicate key" --- src/index.js | 18 ++++++++++++++---- test/index.js | 9 +++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index cb514c3..f5ed059 100644 --- a/src/index.js +++ b/src/index.js @@ -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 { @@ -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 diff --git a/test/index.js b/test/index.js index 8623e5c..f43eb12 100644 --- a/test/index.js +++ b/test/index.js @@ -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: {} }));