mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-01 13:32:23 +02:00
Fix further tests
This commit is contained in:
parent
8e703b5bfc
commit
098f71172d
|
@ -20,30 +20,35 @@ function ignoreExtensions(extensions = [], returnValue = {}) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function mockStorage() {
|
function mockRAF(global) {
|
||||||
return {
|
let callbacksQueue = [];
|
||||||
removeItem: function(key) {
|
|
||||||
delete this[key];
|
global.setInterval(() => {
|
||||||
},
|
for (let i = 0; i < callbacksQueue.length; i++) {
|
||||||
getItem: function(key) {
|
if (callbacksQueue[i] !== false) {
|
||||||
return this[key];
|
callbacksQueue[i].call(null);
|
||||||
},
|
}
|
||||||
setItem: function(key, value) {
|
}
|
||||||
this[key] = value;
|
|
||||||
},
|
callbacksQueue = [];
|
||||||
clear: function() {}
|
}, 1000 / 60);
|
||||||
}
|
|
||||||
|
global.requestAnimationFrame = callback => callbacksQueue.push(callback) - 1;
|
||||||
|
|
||||||
|
global.cancelAnimationFrame = (id) => {
|
||||||
|
callbacksQueue[id] = false;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
global.window = window;
|
global.window = window;
|
||||||
global.document = window.document;
|
global.document = window.document;
|
||||||
global.navigator = {
|
global.navigator = {
|
||||||
userAgent: 'node.js'
|
userAgent: 'node.js',
|
||||||
};
|
};
|
||||||
global.HTMLElement = window.HTMLElement;
|
global.HTMLElement = window.HTMLElement;
|
||||||
global.window.localStorage = mockStorage;
|
|
||||||
global.window.sessionStorage = mockStorage;
|
|
||||||
|
|
||||||
copyProps(window, global);
|
copyProps(window, global);
|
||||||
|
mockRAF(global);
|
||||||
|
|
||||||
ignoreExtensions(['.scss', '.css']);
|
ignoreExtensions(['.scss', '.css']);
|
||||||
ignoreExtensions(['.jpg', '.png', '.svg'], '');
|
ignoreExtensions(['.jpg', '.png', '.svg'], '');
|
||||||
|
|
|
@ -380,7 +380,7 @@ describe('Choices', () => {
|
||||||
preventDefault: () => {},
|
preventDefault: () => {},
|
||||||
});
|
});
|
||||||
|
|
||||||
const returnValue = onChangeStub.calls.mostRecent().args[0].detail.value;
|
const returnValue = onChangeStub.lastCall.args[0].detail.value;
|
||||||
expect(returnValue).to.be.a('string');
|
expect(returnValue).to.be.a('string');
|
||||||
expect(onChangeStub.callCount).to.equal(1);
|
expect(onChangeStub.callCount).to.equal(1);
|
||||||
expect(addSpyStub.callCount).to.equal(1);
|
expect(addSpyStub.callCount).to.equal(1);
|
||||||
|
@ -473,7 +473,7 @@ describe('Choices', () => {
|
||||||
passedElement.addEventListener('search', onSearchStub);
|
passedElement.addEventListener('search', onSearchStub);
|
||||||
|
|
||||||
instance.input.element.focus();
|
instance.input.element.focus();
|
||||||
instance.input.value = '3 ';
|
instance.input.element.value = '3 ';
|
||||||
|
|
||||||
// Key down to search
|
// Key down to search
|
||||||
instance._onKeyUp({
|
instance._onKeyUp({
|
||||||
|
@ -482,9 +482,9 @@ describe('Choices', () => {
|
||||||
ctrlKey: false,
|
ctrlKey: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const mostAccurateResult = instance.currentState.choices.filter(choice => choice.active);
|
const mostAccurateResult = instance.currentState.choices.find(choice => choice.active);
|
||||||
|
|
||||||
expect(instance.isSearching && mostAccurateResult[0].value === 'Value 3').to.be.true;
|
expect(instance.isSearching && mostAccurateResult.value === 'Value 3').to.be.true;
|
||||||
expect(onSearchStub.callCount).to.equal(1);
|
expect(onSearchStub.callCount).to.equal(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ export default class Container {
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
shouldFlip(dropdownPos) {
|
shouldFlip(dropdownPos) {
|
||||||
if (!dropdownPos) {
|
if (dropdownPos === undefined) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue