mirror of
https://github.com/Choices-js/Choices.git
synced 2024-05-01 21:42:46 +02:00
* use template from instance * adjust test * fix lint * try to move `this` out of loop * fixes late init bound
This commit is contained in:
parent
4e8842d013
commit
7de0887e7d
|
@ -101,6 +101,7 @@ class Choices {
|
|||
this.passedElement = new WrappedSelect({
|
||||
element: passedElement,
|
||||
classNames: this.config.classNames,
|
||||
template: data => this.config.templates.option(data),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import WrappedElement from './wrapped-element';
|
||||
import templates from './../templates';
|
||||
|
||||
export default class WrappedSelect extends WrappedElement {
|
||||
constructor({ element, classNames }) {
|
||||
constructor({ element, classNames, template }) {
|
||||
super({ element, classNames });
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
get placeholderOption() {
|
||||
|
@ -22,9 +22,9 @@ export default class WrappedSelect extends WrappedElement {
|
|||
const fragment = document.createDocumentFragment();
|
||||
const addOptionToFragment = data => {
|
||||
// Create a standard select option
|
||||
const template = templates.option(data);
|
||||
const option = this.template(data);
|
||||
// Append it to fragment
|
||||
fragment.appendChild(template);
|
||||
fragment.appendChild(option);
|
||||
};
|
||||
|
||||
// Add each list item to list
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { expect } from 'chai';
|
||||
import { stub } from 'sinon';
|
||||
import { stub, spy } from 'sinon';
|
||||
import WrappedElement from './wrapped-element';
|
||||
import WrappedSelect from './wrapped-select';
|
||||
import { DEFAULT_CLASSNAMES } from '../constants';
|
||||
import Templates from '../templates';
|
||||
|
||||
describe('components/wrappedSelect', () => {
|
||||
let instance;
|
||||
|
@ -28,6 +29,7 @@ describe('components/wrappedSelect', () => {
|
|||
instance = new WrappedSelect({
|
||||
element: document.getElementById('target'),
|
||||
classNames: DEFAULT_CLASSNAMES,
|
||||
template: spy(Templates.option),
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -133,6 +135,7 @@ describe('components/wrappedSelect', () => {
|
|||
selectElement.appendChild(fragment);
|
||||
|
||||
expect(fragment).to.be.instanceOf(DocumentFragment);
|
||||
expect(instance.template.callCount).to.equal(2);
|
||||
expect(selectElement.options.length).to.equal(2);
|
||||
expect(selectElement.options[0].value).to.equal(options[0].value);
|
||||
expect(selectElement.options[1].value).to.equal(options[1].value);
|
||||
|
|
Loading…
Reference in a new issue