Skip to content

Commit

Permalink
Fix buildSelect + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vidartf committed Oct 5, 2021
1 parent d68aed3 commit 33e9c67
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/nbdime/src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ function buildSelect(options: string[], select?: HTMLSelectElement): HTMLSelectE
}
for (let option of options) {
let opt = document.createElement('option');
opt.value = opt.innerText = option;
opt.text = option;
select.appendChild(opt);
}
return select;
Expand Down
30 changes: 30 additions & 0 deletions packages/nbdime/test/src/common/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,36 @@ describe('common', () => {

});

describe('buildSelect', () => {

it('should create an empty select', () => {
let value = util.buildSelect([]);
expect(value.outerHTML).toEqual("<select></select>");
});

it('should reuse a given select', () => {
const select = document.createElement('select');
let value = util.buildSelect([], select);
expect(value).toBe(select);
});

it('should create a select with options', () => {
let value = util.buildSelect([
'foo',
'bar',
'<div>boo</div>'
]);
expect(value.outerHTML).toEqual(
'<select>' +
'<option>foo</option>' +
'<option>bar</option>' +
'<option>&lt;div&gt;boo&lt;/div&gt;</option>' +
'</select>'
);
});

});

});

});

0 comments on commit 33e9c67

Please sign in to comment.