Skip to content

Commit 586ea16

Browse files
committed
Fixed addOptionGroup method (typo) + added tests (#85).
1 parent f937acd commit 586ea16

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

src/selectize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ $.extend(Selectize.prototype, {
978978
*/
979979
addOptionGroup: function(id, data) {
980980
this.optgroups[id] = data;
981-
this.trigger('optgroup_add', value, data);
981+
this.trigger('optgroup_add', id, data);
982982
},
983983

984984
/**

test/api.js

+15
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,21 @@
138138
});
139139
});
140140

141+
describe('addOptionGroup()', function() {
142+
before(function() {
143+
test = setup_test('<select>', {valueField: 'value', labelField: 'value'});
144+
});
145+
after(function() {
146+
test.teardown();
147+
});
148+
it('should register group', function() {
149+
var data = {label: 'Group Label'};
150+
test.selectize.addOptionGroup('group_id', data);
151+
expect(test.selectize.optgroups).to.have.property('group_id');
152+
expect(test.selectize.optgroups['group_id']).to.eql(data);
153+
});
154+
});
155+
141156
describe('addOption()', function() {
142157
before(function() {
143158
test = setup_test('<select>', {valueField: 'value', labelField: 'value'});

test/events.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,34 @@ describe('Events', function() {
8787
});
8888
});
8989

90+
describe('optgroup_add', function() {
91+
beforeEach(function() {
92+
test = setup_test('<select><option value="a" selected></option><option value="b" selected></option><option value="c"></option></select>', {});
93+
});
94+
afterEach(function() {
95+
test.teardown();
96+
});
97+
it('should be triggered', function(done) {
98+
test.selectize.on('optgroup_add', function() { done(); });
99+
test.selectize.addOptionGroup('id', {label: 'Group'});
100+
});
101+
it('should contain optgroup id', function(done) {
102+
test.selectize.on('optgroup_add', function(id, data) {
103+
expect(id).to.be.equal('id');
104+
done();
105+
});
106+
test.selectize.addOptionGroup('id', {label: 'Group'});
107+
});
108+
it('should contain outgroup data', function(done) {
109+
var optgroup = {label: 'Group'};
110+
test.selectize.on('optgroup_add', function(id, data) {
111+
expect(data).to.eql(optgroup);
112+
done();
113+
});
114+
test.selectize.addOptionGroup('id', optgroup);
115+
});
116+
});
117+
90118
describe('option_add', function() {
91119
beforeEach(function() {
92120
test = setup_test('<select><option value="a" selected></option><option value="b" selected></option><option value="c"></option></select>', {});
@@ -110,7 +138,7 @@ describe('Events', function() {
110138
it('should contain option data', function(done) {
111139
var option = {value: 'e'};
112140
test.selectize.on('option_add', function(value, data) {
113-
expect(data).to.be.equal(data);
141+
expect(option).to.eql(data);
114142
done();
115143
});
116144
test.selectize.addOption(option);

0 commit comments

Comments
 (0)