From 4f121a0dca253499d5fab82e8185b9d9ce1fc662 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Thu, 28 Nov 2019 21:00:20 +0000 Subject: [PATCH 1/8] Add CLEAR_ITEMS action --- src/scripts/constants.js | 1 + src/scripts/constants.test.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/scripts/constants.js b/src/scripts/constants.js index 5718c1c3f..3d6ace635 100644 --- a/src/scripts/constants.js +++ b/src/scripts/constants.js @@ -104,6 +104,7 @@ export const ACTION_TYPES = { ADD_ITEM: 'ADD_ITEM', REMOVE_ITEM: 'REMOVE_ITEM', HIGHLIGHT_ITEM: 'HIGHLIGHT_ITEM', + CLEAR_ITEMS: 'CLEAR_ITEMS', CLEAR_ALL: 'CLEAR_ALL', }; diff --git a/src/scripts/constants.test.js b/src/scripts/constants.test.js index 3579dcb81..83a78a550 100644 --- a/src/scripts/constants.test.js +++ b/src/scripts/constants.test.js @@ -120,6 +120,7 @@ describe('constants', () => { 'ADD_ITEM', 'REMOVE_ITEM', 'HIGHLIGHT_ITEM', + 'CLEAR_ITEMS', 'CLEAR_ALL', ]); }); From 9a8686bccc82f03bc463c35ce71f71fae9237e3d Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Thu, 28 Nov 2019 21:01:29 +0000 Subject: [PATCH 2/8] Add clearItems action --- src/scripts/actions/items.js | 7 +++++++ src/scripts/actions/items.test.js | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/scripts/actions/items.js b/src/scripts/actions/items.js index e28075925..424da3762 100644 --- a/src/scripts/actions/items.js +++ b/src/scripts/actions/items.js @@ -51,3 +51,10 @@ export const highlightItem = (id, highlighted) => ({ id, highlighted, }); + +/** + * @returns {Action} + */ +export const clearItems = () => ({ + type: ACTION_TYPES.CLEAR_ITEMS, +}); diff --git a/src/scripts/actions/items.test.js b/src/scripts/actions/items.test.js index c637975b3..a5f9310a9 100644 --- a/src/scripts/actions/items.test.js +++ b/src/scripts/actions/items.test.js @@ -68,4 +68,14 @@ describe('actions/items', () => { expect(actions.highlightItem(id, highlighted)).to.eql(expectedAction); }); }); + + describe('clearItems action', () => { + it('returns CLEAR_ITEMS action', () => { + const expectedAction = { + type: 'CLEAR_ITEMS', + }; + + expect(actions.clearItems()).to.eql(expectedAction); + }); + }); }); From 862e1a52eb1f1808a68622d5f905879144c2fd17 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Thu, 28 Nov 2019 21:02:45 +0000 Subject: [PATCH 3/8] Add CLEAR_ITEMS to reducer --- src/scripts/reducers/items.js | 4 ++++ src/scripts/reducers/items.test.js | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/scripts/reducers/items.js b/src/scripts/reducers/items.js index 2a520f9d2..79e2b00e1 100644 --- a/src/scripts/reducers/items.js +++ b/src/scripts/reducers/items.js @@ -51,6 +51,10 @@ export default function items(state = defaultState, action) { }); } + case 'CLEAR_ITEMS': { + return defaultState; + } + default: { return state; } diff --git a/src/scripts/reducers/items.test.js b/src/scripts/reducers/items.test.js index 4041a3b3e..00425e37e 100644 --- a/src/scripts/reducers/items.test.js +++ b/src/scripts/reducers/items.test.js @@ -177,5 +177,17 @@ describe('reducers/items', () => { expect(actualResponse).to.eql(expectedResponse); }); }); + + describe('CLEAR_ITEMS', () => { + it('restores to defaultState', () => { + const clonedState = state.slice(0); + const expectedResponse = defaultState; + const actualResponse = items(clonedState, { + type: 'CLEAR_ITEMS', + }); + + expect(actualResponse).to.eql(expectedResponse); + }); + }); }); }); From 9be164e2e5475420a36cea58fdd2116631758bc1 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Thu, 28 Nov 2019 21:12:33 +0000 Subject: [PATCH 4/8] Add clearItems method + update setChoices --- README.md | 22 +++++-- src/scripts/choices.js | 26 ++++++-- src/scripts/choices.test.js | 124 ++++++++++++++++++++++++------------ types/index.d.ts | 4 +- 4 files changed, 125 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 77e0b02f2..c2c04d454 100644 --- a/README.md +++ b/README.md @@ -824,12 +824,6 @@ choices.setValue(['Set value 1', 'Set value 2']); choices.disable(); ``` -### destroy(); - -**Input types affected:** `text`, `select-multiple`, `select-one` - -**Usage:** Kills the instance of Choices, removes all event listeners and returns passed input to its initial state. - ### init(); **Input types affected:** `text`, `select-multiple`, `select-one` @@ -838,6 +832,12 @@ choices.disable(); **Note:** This is called implicitly when a new instance of Choices is created. This would be used after a Choices instance had already been destroyed (using `destroy()`). +### destroy(); + +**Input types affected:** `text`, `select-multiple`, `select-one` + +**Usage:** Kills the instance of Choices, removes all event listeners and returns passed input to its initial state. + ### highlightAll(); **Input types affected:** `text`, `select-multiple` @@ -880,7 +880,7 @@ choices.disable(); **Usage:** Hide option list dropdown (only affects select inputs). -### setChoices(choices, value, label, replaceChoices); +### setChoices(choices[, value[, label[, replaceChoices[, replaceItems]]]]); **Input types affected:** `select-one`, `select-multiple` @@ -902,6 +902,7 @@ example.setChoices( 'value', 'label', false, + true, ); ``` @@ -959,6 +960,7 @@ example.setChoices( 'value', 'label', false, + true, ); ``` @@ -968,6 +970,12 @@ example.setChoices( **Usage:** Clear all choices from select +### clearItems(); + +**Input types affected:** `select-one`, `select-multiple` + +**Usage:** Clear all items from select + ### getValue(valueOnly) **Input types affected:** `text`, `select-one`, `select-multiple` diff --git a/src/scripts/choices.js b/src/scripts/choices.js index a88982929..e47485d18 100644 --- a/src/scripts/choices.js +++ b/src/scripts/choices.js @@ -25,7 +25,12 @@ import { activateChoices, clearChoices, } from './actions/choices'; -import { addItem, removeItem, highlightItem } from './actions/items'; +import { + addItem, + removeItem, + highlightItem, + clearItems, +} from './actions/items'; import { addGroup } from './actions/groups'; import { clearAll, resetTo, setIsLoading } from './actions/misc'; import { @@ -496,7 +501,8 @@ class Choices { * @param {T} [choicesArrayOrFetcher] * @param {string} [value = 'value'] - name of `value` field * @param {string} [label = 'label'] - name of 'label' field - * @param {boolean} [replaceChoices = false] - whether to replace of add choices + * @param {boolean} [replaceChoices = false] - whether to clear existing choices + * @param {boolean} [replaceItems = false] - whether to clear existing items * @returns {this | Promise} * * @example @@ -558,6 +564,7 @@ class Choices { value = 'value', label = 'label', replaceChoices = false, + replaceItems = false, ) { if (!this.initialised) { throw new ReferenceError( @@ -574,11 +581,14 @@ class Choices { ); } - // Clear choices if needed if (replaceChoices) { this.clearChoices(); } + if (replaceItems) { + this.clearItems(); + } + if (typeof choicesArrayOrFetcher === 'function') { // it's a choices fetcher function const fetcher = choicesArrayOrFetcher(this); @@ -589,7 +599,9 @@ class Choices { return new Promise(resolve => requestAnimationFrame(resolve)) .then(() => this._handleLoadingState(true)) .then(() => fetcher) - .then(data => this.setChoices(data, value, label, replaceChoices)) + .then(data => + this.setChoices(data, value, label, replaceChoices, replaceItems), + ) .catch(err => { if (!this.config.silent) { console.error(err); @@ -651,6 +663,12 @@ class Choices { return this; } + clearItems() { + this._store.dispatch(clearItems()); + + return this; + } + clearStore() { this._store.dispatch(clearAll()); diff --git a/src/scripts/choices.test.js b/src/scripts/choices.test.js index f5c0bd117..a1a28d6c6 100644 --- a/src/scripts/choices.test.js +++ b/src/scripts/choices.test.js @@ -28,12 +28,6 @@ describe('choices', () => { instance = null; }); - const returnsInstance = () => { - it('returns this', () => { - expect(output).to.eql(instance); - }); - }; - describe('constructor', () => { describe('config', () => { describe('not passing config options', () => { @@ -88,6 +82,7 @@ describe('choices', () => { `; instance = new Choices('[data-choice]', { + // @ts-ignore renderSelectedChoices: 'test', }); @@ -423,7 +418,9 @@ describe('choices', () => { output = instance.enable(); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('returns early', () => { expect(passedElementEnableSpy.called).to.equal(false); @@ -481,7 +478,9 @@ describe('choices', () => { output = instance.disable(); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('returns early', () => { expect(removeEventListenersSpy.called).to.equal(false); @@ -638,7 +637,9 @@ describe('choices', () => { output = instance.hideDropdown(); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('returns early', () => { expect(containerOuterCloseSpy.called).to.equal(false); @@ -735,7 +736,9 @@ describe('choices', () => { output = instance.highlightItem(); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('returns early', () => { expect(passedElementTriggerEventStub.called).to.equal(false); @@ -756,7 +759,9 @@ describe('choices', () => { output = instance.highlightItem(item, true); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('dispatches highlightItem action with correct arguments', () => { expect(storeDispatchSpy.called).to.equal(true); @@ -817,7 +822,9 @@ describe('choices', () => { expect(passedElementTriggerEventStub.called).to.equal(false); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); }); }); }); @@ -850,7 +857,9 @@ describe('choices', () => { output = instance.unhighlightItem(); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('returns early', () => { expect(passedElementTriggerEventStub.called).to.equal(false); @@ -871,7 +880,9 @@ describe('choices', () => { output = instance.unhighlightItem(item, true); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('dispatches highlightItem action with correct arguments', () => { expect(storeDispatchSpy.called).to.equal(true); @@ -932,7 +943,9 @@ describe('choices', () => { expect(passedElementTriggerEventStub.called).to.equal(false); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); }); }); }); @@ -966,7 +979,9 @@ describe('choices', () => { storeGetItemsStub.reset(); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('highlights each item in store', () => { expect(highlightItemStub.callCount).to.equal(items.length); @@ -1004,7 +1019,9 @@ describe('choices', () => { storeGetItemsStub.reset(); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('unhighlights each item in store', () => { expect(unhighlightItemStub.callCount).to.equal(items.length); @@ -1027,7 +1044,9 @@ describe('choices', () => { instance._store.dispatch.reset(); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('dispatches clearChoices action', () => { expect(storeDispatchStub.lastCall.args[0]).to.eql({ @@ -1050,7 +1069,9 @@ describe('choices', () => { instance._store.dispatch.reset(); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('dispatches clearAll action', () => { expect(storeDispatchStub.lastCall.args[0]).to.eql({ @@ -1075,7 +1096,9 @@ describe('choices', () => { instance._store.dispatch.reset(); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); describe('text element', () => { beforeEach(() => { @@ -1211,7 +1234,9 @@ describe('choices', () => { output = instance.setValue(values); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('returns early', () => { expect(setChoiceOrItemStub.called).to.equal(false); @@ -1224,7 +1249,9 @@ describe('choices', () => { output = instance.setValue(values); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('sets each value', () => { expect(setChoiceOrItemStub.callCount).to.equal(2); @@ -1252,7 +1279,9 @@ describe('choices', () => { output = instance.setChoiceByValue([]); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('returns early', () => { expect(findAndSelectChoiceByValueStub.called).to.equal(false); @@ -1272,7 +1301,9 @@ describe('choices', () => { output = instance.setChoiceByValue(value); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('sets each choice with same value', () => { expect(findAndSelectChoiceByValueStub.called).to.equal(true); @@ -1289,7 +1320,9 @@ describe('choices', () => { output = instance.setChoiceByValue(values); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('sets each choice with same value', () => { expect(findAndSelectChoiceByValueStub.callCount).to.equal(2); @@ -1509,7 +1542,9 @@ describe('choices', () => { output = instance.removeHighlightedItems(); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('removes each highlighted item in store', () => { expect(removeItemStub.callCount).to.equal(2); @@ -1521,7 +1556,9 @@ describe('choices', () => { output = instance.removeHighlightedItems(true); }); - returnsInstance(output); + it('returns this', () => { + expect(output).to.eql(instance); + }); it('triggers event with item value', () => { expect(triggerChangeStub.callCount).to.equal(2); @@ -1533,6 +1570,7 @@ describe('choices', () => { describe('setChoices', () => { let clearChoicesStub; + let clearItemsStub; let addGroupStub; let addChoiceStub; let containerOuterRemoveLoadingStateStub; @@ -1560,11 +1598,13 @@ describe('choices', () => { beforeEach(() => { clearChoicesStub = stub(); + clearItemsStub = stub(); addGroupStub = stub(); addChoiceStub = stub(); containerOuterRemoveLoadingStateStub = stub(); instance.clearChoices = clearChoicesStub; + instance.clearItems = clearItemsStub; instance._addGroup = addGroupStub; instance._addChoice = addChoiceStub; instance.containerOuter.removeLoadingState = containerOuterRemoveLoadingStateStub; @@ -1595,7 +1635,7 @@ describe('choices', () => { instance._isSelectElement = true; }); - it('throws', () => { + it('throws a TypeError', () => { expect(() => instance.setChoices(choices, null, 'label', false), ).to.throw(TypeError, /value/i); @@ -1643,16 +1683,8 @@ describe('choices', () => { }); }); - describe('passing an empty array with a true replaceChoices flag', () => { - it('choices are cleared', () => { - instance._isSelectElement = true; - instance.setChoices([], value, label, true); - expect(clearChoicesStub.called).to.equal(true); - }); - }); - describe('passing an empty array with a false replaceChoices flag', () => { - it('choices stay the same', () => { + it('does not clear existing choices', () => { instance._isSelectElement = true; instance.setChoices([], value, label, false); expect(clearChoicesStub.called).to.equal(false); @@ -1660,18 +1692,32 @@ describe('choices', () => { }); describe('passing true replaceChoices flag', () => { - it('choices are cleared', () => { + it('clears existing choices', () => { instance.setChoices(choices, value, label, true); expect(clearChoicesStub.called).to.equal(true); }); }); describe('passing false replaceChoices flag', () => { - it('choices are not cleared', () => { + it('clears existing choices are not cleared', () => { instance.setChoices(choices, value, label, false); expect(clearChoicesStub.called).to.equal(false); }); }); + + describe('passing true replaceItems flag', () => { + it('clears existing items', () => { + instance.setChoices(choices, value, label, true, true); + expect(clearItemsStub.called).to.equal(true); + }); + }); + + describe('passing false replaceItems flag', () => { + it('does not clears existing items', () => { + instance.setChoices(choices, value, label, true, false); + expect(clearItemsStub.called).to.equal(false); + }); + }); }); }); }); diff --git a/types/index.d.ts b/types/index.d.ts index d3520bdfd..942cb4f86 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -933,7 +933,8 @@ export default class Choices { * * @param {string} [value = 'value'] - name of `value` field * @param {string} [label = 'label'] - name of 'label' field - * @param {boolean} [replaceChoices = false] - whether to replace of add choices + * @param {boolean} [replaceChoices = false] - whether to clear existing choices + * @param {boolean} [replaceItems = false] - whether to clear existing items * * @example * ```js @@ -996,6 +997,7 @@ export default class Choices { value?: string, label?: string, replaceChoices?: boolean, + replaceItems?: boolean, ): T extends object[] ? this : Promise; /** From a57eb3e689341f68b3f31fe241506b4fc652c264 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Thu, 28 Nov 2019 21:19:25 +0000 Subject: [PATCH 5/8] Update test descriptions --- src/scripts/choices.test.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/scripts/choices.test.js b/src/scripts/choices.test.js index a1a28d6c6..207e9a359 100644 --- a/src/scripts/choices.test.js +++ b/src/scripts/choices.test.js @@ -1148,8 +1148,8 @@ describe('choices', () => { instance.initialised = false; }); - it('should throw', () => { - expect(() => instance.setChoices(null)).Throw(ReferenceError); + it('throws a ReferenceError', () => { + expect(() => instance.setChoices(null)).to.throw(ReferenceError); }); }); @@ -1158,8 +1158,8 @@ describe('choices', () => { instance._isSelectElement = false; }); - it('should throw', () => { - expect(() => instance.setChoices(null)).Throw(TypeError); + it('throws a TypeError', () => { + expect(() => instance.setChoices([])).to.throw(TypeError); }); }); @@ -1168,15 +1168,22 @@ describe('choices', () => { instance._isSelectElement = true; }); - it('should throw on non function', () => { - expect(() => instance.setChoices(null)).Throw(TypeError, /Promise/i); + describe('passing a non-function', () => { + it('throws a TypeError', () => { + expect(() => instance.setChoices(null)).to.throw( + TypeError, + /Promise/i, + ); + }); }); - it(`should throw on function that doesn't return promise`, () => { - expect(() => instance.setChoices(() => 'boo')).to.throw( - TypeError, - /promise/i, - ); + describe('passing a function that does not return a promise', () => { + it('throws a TypeError', () => { + expect(() => instance.setChoices(() => 'boo')).to.throw( + TypeError, + /promise/i, + ); + }); }); }); From 35cabbe985e4be90120f3bdf6d236083a610c215 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Thu, 28 Nov 2019 21:20:36 +0000 Subject: [PATCH 6/8] Add tests for clearItems --- src/scripts/choices.test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/scripts/choices.test.js b/src/scripts/choices.test.js index 207e9a359..73c75b4e7 100644 --- a/src/scripts/choices.test.js +++ b/src/scripts/choices.test.js @@ -1055,6 +1055,31 @@ describe('choices', () => { }); }); + describe('clearItems', () => { + let storeDispatchStub; + + beforeEach(() => { + storeDispatchStub = stub(); + instance._store.dispatch = storeDispatchStub; + + output = instance.clearItems(); + }); + + afterEach(() => { + instance._store.dispatch.reset(); + }); + + it('returns this', () => { + expect(output).to.eql(instance); + }); + + it('dispatches clearItems action', () => { + expect(storeDispatchStub.lastCall.args[0]).to.eql({ + type: ACTION_TYPES.CLEAR_ITEMS, + }); + }); + }); + describe('clearStore', () => { let storeDispatchStub; From c64a7ca04ca97c197f01f9c3c029a9fc57dfd7e8 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Thu, 28 Nov 2019 21:37:55 +0000 Subject: [PATCH 7/8] Clear items by default instead --- README.md | 4 +--- src/scripts/choices.js | 9 +-------- src/scripts/choices.test.js | 34 ++++++++++++++++++++-------------- types/index.d.ts | 2 -- 4 files changed, 22 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index c2c04d454..faa77ff72 100644 --- a/README.md +++ b/README.md @@ -880,7 +880,7 @@ choices.disable(); **Usage:** Hide option list dropdown (only affects select inputs). -### setChoices(choices[, value[, label[, replaceChoices[, replaceItems]]]]); +### setChoices(choices[, value[, label[, replaceChoices]]]); **Input types affected:** `select-one`, `select-multiple` @@ -902,7 +902,6 @@ example.setChoices( 'value', 'label', false, - true, ); ``` @@ -960,7 +959,6 @@ example.setChoices( 'value', 'label', false, - true, ); ``` diff --git a/src/scripts/choices.js b/src/scripts/choices.js index e47485d18..1f1fec2d9 100644 --- a/src/scripts/choices.js +++ b/src/scripts/choices.js @@ -502,7 +502,6 @@ class Choices { * @param {string} [value = 'value'] - name of `value` field * @param {string} [label = 'label'] - name of 'label' field * @param {boolean} [replaceChoices = false] - whether to clear existing choices - * @param {boolean} [replaceItems = false] - whether to clear existing items * @returns {this | Promise} * * @example @@ -564,7 +563,6 @@ class Choices { value = 'value', label = 'label', replaceChoices = false, - replaceItems = false, ) { if (!this.initialised) { throw new ReferenceError( @@ -583,9 +581,6 @@ class Choices { if (replaceChoices) { this.clearChoices(); - } - - if (replaceItems) { this.clearItems(); } @@ -599,9 +594,7 @@ class Choices { return new Promise(resolve => requestAnimationFrame(resolve)) .then(() => this._handleLoadingState(true)) .then(() => fetcher) - .then(data => - this.setChoices(data, value, label, replaceChoices, replaceItems), - ) + .then(data => this.setChoices(data, value, label, replaceChoices)) .catch(err => { if (!this.config.silent) { console.error(err); diff --git a/src/scripts/choices.test.js b/src/scripts/choices.test.js index 73c75b4e7..e472ead03 100644 --- a/src/scripts/choices.test.js +++ b/src/scripts/choices.test.js @@ -1716,37 +1716,43 @@ describe('choices', () => { }); describe('passing an empty array with a false replaceChoices flag', () => { - it('does not clear existing choices', () => { - instance._isSelectElement = true; + beforeEach(() => { instance.setChoices([], value, label, false); + }); + + it('does not clear existing choices', () => { expect(clearChoicesStub.called).to.equal(false); }); + + it('does not clear existing items', () => { + expect(clearItemsStub.called).to.equal(false); + }); }); describe('passing true replaceChoices flag', () => { - it('clears existing choices', () => { + beforeEach(() => { instance.setChoices(choices, value, label, true); + }); + + it('clears existing choices', () => { expect(clearChoicesStub.called).to.equal(true); }); + + it('clears existing items', () => { + expect(clearItemsStub.called).to.equal(true); + }); }); describe('passing false replaceChoices flag', () => { - it('clears existing choices are not cleared', () => { + beforeEach(() => { instance.setChoices(choices, value, label, false); - expect(clearChoicesStub.called).to.equal(false); }); - }); - describe('passing true replaceItems flag', () => { - it('clears existing items', () => { - instance.setChoices(choices, value, label, true, true); - expect(clearItemsStub.called).to.equal(true); + it('does not clear existing choices', () => { + expect(clearChoicesStub.called).to.equal(false); }); - }); - describe('passing false replaceItems flag', () => { - it('does not clears existing items', () => { - instance.setChoices(choices, value, label, true, false); + it('does not clear existing items', () => { expect(clearItemsStub.called).to.equal(false); }); }); diff --git a/types/index.d.ts b/types/index.d.ts index 942cb4f86..5e0f94e92 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -934,7 +934,6 @@ export default class Choices { * @param {string} [value = 'value'] - name of `value` field * @param {string} [label = 'label'] - name of 'label' field * @param {boolean} [replaceChoices = false] - whether to clear existing choices - * @param {boolean} [replaceItems = false] - whether to clear existing items * * @example * ```js @@ -997,7 +996,6 @@ export default class Choices { value?: string, label?: string, replaceChoices?: boolean, - replaceItems?: boolean, ): T extends object[] ? this : Promise; /** From c18821227c1eea721127ff0d3a471c162ceb2f54 Mon Sep 17 00:00:00 2001 From: Josh Johnson Date: Thu, 28 Nov 2019 21:41:26 +0000 Subject: [PATCH 8/8] Update README --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index faa77ff72..832de52b6 100644 --- a/README.md +++ b/README.md @@ -966,13 +966,13 @@ example.setChoices( **Input types affected:** `select-one`, `select-multiple` -**Usage:** Clear all choices from select +**Usage:** Clear all choices ### clearItems(); -**Input types affected:** `select-one`, `select-multiple` +**Input types affected:** `text`, `select-one`, `select-multiple` -**Usage:** Clear all items from select +**Usage:** Clear all items ### getValue(valueOnly)