mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-18 13:45:12 +02:00
Add list unit tests
This commit is contained in:
parent
d211cf9507
commit
f9303d86b0
|
@ -18,10 +18,9 @@ export default class List {
|
|||
/**
|
||||
* Scroll to passed position on Y axis
|
||||
*/
|
||||
scrollTo(scrollPos) {
|
||||
scrollTo(scrollPos = 0) {
|
||||
this.element.scrollTop = scrollPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Append node to element
|
||||
*/
|
||||
|
|
|
@ -14,7 +14,7 @@ describe('List', () => {
|
|||
...DEFAULT_CONFIG,
|
||||
},
|
||||
};
|
||||
choicesElement = document.createElement('select');
|
||||
choicesElement = document.createElement('div');
|
||||
instance = new List(choicesInstance, choicesElement, DEFAULT_CLASSNAMES);
|
||||
});
|
||||
|
||||
|
@ -29,4 +29,52 @@ describe('List', () => {
|
|||
it('assigns classnames to class', () => {
|
||||
expect(instance.classNames).to.eql(DEFAULT_CLASSNAMES);
|
||||
});
|
||||
|
||||
describe('clear', () => {
|
||||
it('clears element\'s inner HTML', () => {
|
||||
const innerHTML = 'test';
|
||||
instance.element.innerHTML = innerHTML;
|
||||
expect(instance.element.innerHTML).to.equal(innerHTML);
|
||||
instance.clear();
|
||||
expect(instance.element.innerHTML).to.equal('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('scrollTo', () => {
|
||||
it('scrolls element to passed position', () => {
|
||||
const scrollPosition = 20;
|
||||
expect(instance.element.scrollTop).to.equal(0);
|
||||
instance.scrollTo(scrollPosition);
|
||||
expect(instance.element.scrollTop).to.equal(scrollPosition);
|
||||
});
|
||||
});
|
||||
|
||||
describe('append', () => {
|
||||
it('appends passed node to element', () => {
|
||||
const elementToAppend = document.createElement('span');
|
||||
const childClass = 'test-element';
|
||||
elementToAppend.classList.add(childClass);
|
||||
expect(instance.element.querySelector(`.${childClass}`)).to.equal(null);
|
||||
instance.append(elementToAppend);
|
||||
expect(instance.element.querySelector(`.${childClass}`)).to.equal(elementToAppend);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('getChild', () => {
|
||||
let childElement;
|
||||
const childClass = 'test-element';
|
||||
|
||||
beforeEach(() => {
|
||||
childElement = document.createElement('span');
|
||||
childElement.classList.add(childClass);
|
||||
instance.element.appendChild(childElement);
|
||||
});
|
||||
|
||||
it('returns child element', () => {
|
||||
const expectedResponse = childElement;
|
||||
const actualResponse = instance.getChild(`.${childClass}`);
|
||||
expect(expectedResponse).to.eql(actualResponse);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue