wix-style-react
Version:
wix-style-react
46 lines (36 loc) • 1.62 kB
JavaScript
;
var _mapValue = require('./mapValue');
var _mapValue2 = _interopRequireDefault(_mapValue);
var _sinon = require('sinon');
var _sinon2 = _interopRequireDefault(_sinon);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
describe('mapValue operator', function () {
it('should return an empty object for non-object input', function () {
expect((0, _mapValue2.default)(1)).toEqual({});
expect((0, _mapValue2.default)(true)).toEqual({});
expect((0, _mapValue2.default)('')).toEqual({});
expect((0, _mapValue2.default)(null)).toEqual({});
expect((0, _mapValue2.default)(undefined)).toEqual({});
expect((0, _mapValue2.default)(Symbol.for('foo'))).toEqual({});
});
it('should return an empty object for non-function map function', function () {
expect((0, _mapValue2.default)({ a: 1 }, 'not-a-function')).toEqual({});
});
it('should return given input', function () {
var anObject = { a: 1, b: '2' };
expect((0, _mapValue2.default)(anObject)).toEqual({ a: 1, b: '2' });
});
it('should project input values by map function', function () {
var anObject = { a: 1, b: 2 };
var multiple = function multiple(value) {
return value + value;
};
expect((0, _mapValue2.default)(anObject, multiple)).toEqual({ a: 2, b: 4 });
});
it('should call map function with (value, key, object)', function () {
var anObject = { a: 1 };
var mapFunc = _sinon2.default.spy();
(0, _mapValue2.default)(anObject, mapFunc);
expect(mapFunc.calledWithExactly(1, 'a', anObject)).toBe(true);
});
});