2022-08-11 17:39:37 +03:00
|
|
|
const optionsUtil = require('../../lib/utils/options');
|
2018-11-19 20:08:48 +03:00
|
|
|
|
2022-08-11 17:42:21 +03:00
|
|
|
describe('util/options', function () {
|
2019-08-19 14:41:09 +03:00
|
|
|
it('returns an array with empty string when no parameters are passed', function () {
|
2018-11-19 20:08:48 +03:00
|
|
|
optionsUtil.trimAndLowerCase().should.eql(['']);
|
|
|
|
});
|
|
|
|
|
2019-08-19 14:41:09 +03:00
|
|
|
it('returns single item array', function () {
|
2018-11-19 20:08:48 +03:00
|
|
|
optionsUtil.trimAndLowerCase('butter').should.eql(['butter']);
|
|
|
|
});
|
|
|
|
|
2019-08-19 14:41:09 +03:00
|
|
|
it('returns multiple items in array', function () {
|
2018-11-19 20:08:48 +03:00
|
|
|
optionsUtil.trimAndLowerCase('peanut, butter').should.eql(['peanut', 'butter']);
|
|
|
|
});
|
|
|
|
|
2019-08-19 14:41:09 +03:00
|
|
|
it('lowercases and trims items in the string', function () {
|
2018-11-19 20:08:48 +03:00
|
|
|
optionsUtil.trimAndLowerCase(' PeanUt, buTTer ').should.eql(['peanut', 'butter']);
|
|
|
|
});
|
|
|
|
|
2019-08-19 14:41:09 +03:00
|
|
|
it('accepts parameters in form of an array', function () {
|
2018-11-19 20:08:48 +03:00
|
|
|
optionsUtil.trimAndLowerCase([' PeanUt', ' buTTer ']).should.eql(['peanut', 'butter']);
|
|
|
|
});
|
2024-06-24 11:01:36 +03:00
|
|
|
|
|
|
|
it('throws error for invalid object input', function () {
|
|
|
|
try {
|
|
|
|
optionsUtil.trimAndLowerCase({name: 'peanut'});
|
|
|
|
} catch (err) {
|
|
|
|
err.message.should.eql('Params must be a string or array');
|
|
|
|
}
|
|
|
|
});
|
2018-11-19 20:08:48 +03:00
|
|
|
});
|