Fix failing unit tests

This commit is contained in:
Josh Johnson 2019-12-21 13:59:16 +00:00
parent efb86d59b5
commit 1200d393d4
5 changed files with 29 additions and 44 deletions

View file

@ -1,7 +1,8 @@
require: require:
- 'ts-node/register' - 'ts-node/register'
- './config/jsdom.js' - './config/jsdom.js'
exit: true exit: true
spec: src/**/*.test.ts spec: src/**/*.test.ts
extension:
- ts
- js

View file

@ -13,8 +13,8 @@
"cypress:open": "cypress open", "cypress:open": "cypress open",
"cypress:ci": "cypress run --record --group $GITHUB_REF --ci-build-id $GITHUB_SHA", "cypress:ci": "cypress run --record --group $GITHUB_REF --ci-build-id $GITHUB_SHA",
"test": "run-s test:unit test:e2e", "test": "run-s test:unit test:e2e",
"test:unit": "NODE_ENV=test mocha", "test:unit": "TS_NODE_TRANSPILE_ONLY=true NODE_ENV=test mocha",
"test:unit:watch": "NODE_ENV=test mocha --watch --inspect=5556", "test:unit:watch": "npm run test:unit -- --watch --inspect=5556",
"test:unit:coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text --reporter=text-summary mocha", "test:unit:coverage": "NODE_ENV=test nyc --reporter=lcov --reporter=text --reporter=text-summary mocha",
"test:e2e": "run-p --race start cypress:run", "test:e2e": "run-p --race start cypress:run",
"js:watch": "cross-env NODE_ENV=development node server.js", "js:watch": "cross-env NODE_ENV=development node server.js",

View file

@ -8,6 +8,7 @@ import { EVENTS, ACTION_TYPES, DEFAULT_CONFIG, KEY_CODES } from './constants';
import { WrappedSelect, WrappedInput } from './components/index'; import { WrappedSelect, WrappedInput } from './components/index';
import { removeItem } from './actions/items'; import { removeItem } from './actions/items';
import { Item, Choice, Group } from './interfaces'; import { Item, Choice, Group } from './interfaces';
import templates from './templates';
chai.use(sinonChai); chai.use(sinonChai);
@ -382,8 +383,8 @@ describe('choices', () => {
expect(clearStoreSpy.called).to.equal(true); expect(clearStoreSpy.called).to.equal(true);
}); });
it('nullifys templates config', () => { it('restes templates config', () => {
expect(instance._templates).to.equal(null); expect(instance._templates).to.deep.equal(templates);
}); });
it('resets initialise flag', () => { it('resets initialise flag', () => {
@ -1206,7 +1207,9 @@ describe('choices', () => {
expect(handleLoadingStateSpy.callCount).to.equal(2); expect(handleLoadingStateSpy.callCount).to.equal(2);
expect(choice._store.choices[1].value).to.equal('v2'); expect(choice._store.choices[1].value).to.equal('v2');
expect(choice._store.choices[1].label).to.equal('l2'); expect(choice._store.choices[1].label).to.equal('l2');
expect(choice._store.choices[1].customProperties).to.equal('prop2'); expect(choice._store.choices[1].customProperties).to.deep.equal({
prop2: false,
});
}); });
}); });
}); });
@ -1581,11 +1584,15 @@ describe('choices', () => {
id: 1, id: 1,
value: '1', value: '1',
label: 'Test 1', label: 'Test 1',
selected: false,
disabled: false,
}, },
{ {
id: 2, id: 2,
value: '2', value: '2',
label: 'Test 2', label: 'Test 2',
selected: false,
disabled: true,
}, },
]; ];
const groups: Group[] = [ const groups: Group[] = [
@ -1672,10 +1679,10 @@ describe('choices', () => {
expect(call.args[0]).to.eql({ expect(call.args[0]).to.eql({
value: choices[index][value], value: choices[index][value],
label: choices[index][label], label: choices[index][label],
isSelected: choices[index].selected, isSelected: !!choices[index].selected,
isDisabled: choices[index].disabled, isDisabled: !!choices[index].disabled,
customProperties: choices[index].customProperties, customProperties: choices[index].customProperties,
placeholder: choices[index].placeholder, placeholder: !!choices[index].placeholder,
}); });
}); });
}); });
@ -1963,12 +1970,12 @@ describe('choices', () => {
}); });
describe('when a placeholder option is not defined', () => { describe('when a placeholder option is not defined', () => {
it('returns false', () => { it('returns null', () => {
instance._isSelectElement = true; instance._isSelectElement = true;
instance.passedElement.placeholderOption = undefined; instance.passedElement.placeholderOption = undefined;
const value = instance._generatePlaceholderValue(); const value = instance._generatePlaceholderValue();
expect(value).to.equal(false); expect(value).to.equal(null);
}); });
}); });
}); });
@ -2008,7 +2015,7 @@ describe('choices', () => {
}); });
describe('when the placeholder attribute is not defined on the passed element', () => { describe('when the placeholder attribute is not defined on the passed element', () => {
it('returns false', () => { it('returns null', () => {
instance._isSelectElement = false; instance._isSelectElement = false;
instance.config.placeholder = true; instance.config.placeholder = true;
instance.config.placeholderValue = undefined; instance.config.placeholderValue = undefined;
@ -2019,32 +2026,25 @@ describe('choices', () => {
}; };
const value = instance._generatePlaceholderValue(); const value = instance._generatePlaceholderValue();
expect(value).to.equal(false); expect(value).to.equal(null);
}); });
}); });
}); });
}); });
describe('when the placeholder config option is set to false', () => { describe('when the placeholder config option is set to false', () => {
it('returns false', () => { it('returns null', () => {
instance._isSelectElement = false; instance._isSelectElement = false;
instance.config.placeholder = false; instance.config.placeholder = false;
const value = instance._generatePlaceholderValue(); const value = instance._generatePlaceholderValue();
expect(value).to.equal(false); expect(value).to.equal(null);
}); });
}); });
}); });
}); });
describe('_getTemplate', () => { describe('_getTemplate', () => {
describe('when not passing a template key', () => {
it('returns null', () => {
output = instance._getTemplate();
expect(output).to.equal(null);
});
});
describe('when passing a template key', () => { describe('when passing a template key', () => {
it('returns the generated template for the given template key', () => { it('returns the generated template for the given template key', () => {
const templateKey = 'test'; const templateKey = 'test';

View file

@ -421,7 +421,7 @@ class Choices {
} }
unhighlightAll(): this { unhighlightAll(): this {
this._store.items.forEach(item => this.unhighlightItem(item)); this._store.items.forEach(this.unhighlightItem);
return this; return this;
} }

View file

@ -56,27 +56,11 @@ describe('components/wrappedInput', () => {
}); });
describe('value setter', () => { describe('value setter', () => {
const data = [ it('sets the value of the input to the given value', () => {
{ const newValue = 'Value 1, Value 2, Value 3';
id: 'ID 1',
value: 'Value 1',
},
{
id: 'ID 2',
value: 'Value 2',
},
{
id: 'ID 3',
value: 'Value 3',
},
];
it('sets delimited value of element based on passed data', () => {
expect(instance.element.value).to.equal(''); expect(instance.element.value).to.equal('');
instance.value = data; instance.value = newValue;
expect(instance.value).to.equal( expect(instance.value).to.equal(newValue);
`Value 1${delimiter}Value 2${delimiter}Value 3`,
);
}); });
}); });
}); });