@enact/ui
Version:
A collection of simplified unstyled cross-platform UI components for Enact
106 lines (105 loc) • 3.63 kB
JavaScript
;
var _util = require("../util");
var _this = void 0;
describe('Skinnable/util/objectify Specs', function () {
test('should convert a plain string to an object with one key and value true', function () {
var subject = 'string1';
var expected = {
string1: true
};
var actual = (0, _util.objectify)(subject);
expect(actual).toEqual(expected);
});
test('should convert a string with spaces into an object with 2 keys both with value true', function () {
var subject = 'string1 string2';
var expected = {
string1: true,
string2: true
};
var actual = (0, _util.objectify)(subject);
expect(actual).toEqual(expected);
});
test('should convert an array with one element into an object with one key and value true', function () {
var subject = ['array1'];
var expected = {
array1: true
};
var actual = (0, _util.objectify)(subject);
expect(actual).toEqual(expected);
});
test('should convert an array with two elements into an object with 2 keys both with value true', function () {
var subject = ['array1', 'array2'];
var expected = {
array1: true,
array2: true
};
var actual = (0, _util.objectify)(subject);
expect(actual).toEqual(expected);
});
test('should leave a hash with one key unaltered', function () {
var subject = {
array1: false
};
var expected = {
array1: false
};
var actual = (0, _util.objectify)(subject);
expect(actual).toEqual(expected);
});
test('should leave a hash with two keys unaltered', function () {
var subject = {
array1: false,
array2: false
};
var expected = {
array1: false,
array2: false
};
var actual = (0, _util.objectify)(subject);
expect(actual).toEqual(expected);
});
test('should return an empty object if the argument is falsy', function () {
var subject = '';
var expected = {};
var actual = (0, _util.objectify)(subject);
expect(actual).toEqual(expected);
});
});
describe('Skinnable/util/preferDefined Specs', function () {
test('should return the first element if it is a normal string', function () {
var subject = ['string1', 'string2'];
var expected = 'string1';
var actual = _util.preferDefined.apply(_this, subject);
expect(actual).toEqual(expected);
});
test('should return the first element if even if it is an empty string', function () {
var subject = ['', 'string2'];
var expected = '';
var actual = _util.preferDefined.apply(_this, subject);
expect(actual).toEqual(expected);
});
test('should return the first element if it is a true boolean', function () {
var subject = [true, 'string2'];
var expected = true;
var actual = _util.preferDefined.apply(_this, subject);
expect(actual).toEqual(expected);
});
test('should return the first element if it is a false boolean', function () {
var subject = [false, 'string2'];
var expected = false;
var actual = _util.preferDefined.apply(_this, subject);
expect(actual).toEqual(expected);
});
test('should return the second element if the first is null', function () {
var subject = [null, 'string2'];
var expected = 'string2';
var actual = _util.preferDefined.apply(_this, subject);
expect(actual).toEqual(expected);
});
test('should return the second element if the first is undefined', function () {
var subject = [void 0, 'string2'];
var expected = 'string2';
var actual = _util.preferDefined.apply(_this, subject);
expect(actual).toEqual(expected);
});
});