From af9feb3e2c732706f742455940be1a81ebd55c6d Mon Sep 17 00:00:00 2001 From: Jay Kid Date: Fri, 30 Jun 2017 15:45:47 +0200 Subject: [PATCH] fix: remove extra 'undefined' argument when calling _addItem from _addChoice + Added integration-like test --- assets/scripts/src/choices.js | 4 ++-- tests/spec/choices_spec.js | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/assets/scripts/src/choices.js b/assets/scripts/src/choices.js index 399f30b..4ddfbfb 100644 --- a/assets/scripts/src/choices.js +++ b/assets/scripts/src/choices.js @@ -2205,7 +2205,6 @@ class Choices { choiceLabel, choiceId, undefined, - undefined, customProperties ); } @@ -2254,7 +2253,8 @@ class Choices { label, option.selected, isOptDisabled, - groupId + groupId, + option.customProperties ); }); } else { diff --git a/tests/spec/choices_spec.js b/tests/spec/choices_spec.js index 3afafb2..ce5359d 100644 --- a/tests/spec/choices_spec.js +++ b/tests/spec/choices_spec.js @@ -1038,5 +1038,23 @@ describe('Choices', () => { expect(selectedItems.length).toBe(1); expect(selectedItems[0].customProperties).toBe(expectedCustomProperties); }); + + it('should allow the user to supply custom properties when directly creating a selected item', function() { + const expectedCustomProperties = { + isBestOptionEver: true + }; + + this.choices = new Choices(this.input); + + this.choices.setValue([{ + value: 'bar', + label: 'foo', + customProperties: expectedCustomProperties + }]); + const selectedItems = this.choices.getValue(); + + expect(selectedItems.length).toBe(1); + expect(selectedItems[0].customProperties).toBe(expectedCustomProperties); + }); }); });