Fix further tests

This commit is contained in:
Josh Johnson 2017-09-29 13:26:47 +01:00
parent 8e703b5bfc
commit 098f71172d
3 changed files with 26 additions and 21 deletions

View file

@ -20,30 +20,35 @@ function ignoreExtensions(extensions = [], returnValue = {}) {
});
}
function mockStorage() {
return {
removeItem: function(key) {
delete this[key];
},
getItem: function(key) {
return this[key];
},
setItem: function(key, value) {
this[key] = value;
},
clear: function() {}
}
function mockRAF(global) {
let callbacksQueue = [];
global.setInterval(() => {
for (let i = 0; i < callbacksQueue.length; i++) {
if (callbacksQueue[i] !== false) {
callbacksQueue[i].call(null);
}
}
callbacksQueue = [];
}, 1000 / 60);
global.requestAnimationFrame = callback => callbacksQueue.push(callback) - 1;
global.cancelAnimationFrame = (id) => {
callbacksQueue[id] = false;
};
}
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js'
userAgent: 'node.js',
};
global.HTMLElement = window.HTMLElement;
global.window.localStorage = mockStorage;
global.window.sessionStorage = mockStorage;
copyProps(window, global);
mockRAF(global);
ignoreExtensions(['.scss', '.css']);
ignoreExtensions(['.jpg', '.png', '.svg'], '');

View file

@ -380,7 +380,7 @@ describe('Choices', () => {
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(onChangeStub.callCount).to.equal(1);
expect(addSpyStub.callCount).to.equal(1);
@ -473,7 +473,7 @@ describe('Choices', () => {
passedElement.addEventListener('search', onSearchStub);
instance.input.element.focus();
instance.input.value = '3 ';
instance.input.element.value = '3 ';
// Key down to search
instance._onKeyUp({
@ -482,9 +482,9 @@ describe('Choices', () => {
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);
});

View file

@ -52,7 +52,7 @@ export default class Container {
* @returns
*/
shouldFlip(dropdownPos) {
if (!dropdownPos) {
if (dropdownPos === undefined) {
return false;
}