ts-prime
Version:
A utility library for JavaScript and Typescript.
50 lines (49 loc) • 1.95 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { pick } from './pick';
import { pipe } from './pipe';
describe('data first', function () {
test('it should pick props', function () {
var result = pick({ a: 1, b: 2, c: 3, d: 4 }, ['a', 'd']);
expect(result).toEqual({ a: 1, d: 4 });
});
test('allow undefined or null', function () {
expect(pick(undefined, ['foo'])).toEqual({});
expect(pick(null, ['foo'])).toEqual({});
});
test('support inherited properties', function () {
var BaseClass = /** @class */ (function () {
function BaseClass() {
}
BaseClass.prototype.testProp = function () { return 'abc'; };
;
return BaseClass;
}());
var TestClass = /** @class */ (function (_super) {
__extends(TestClass, _super);
function TestClass() {
return _super !== null && _super.apply(this, arguments) || this;
}
return TestClass;
}(BaseClass));
var testClass = new TestClass();
expect(pick(testClass, ['testProp'])).toEqual({ testProp: expect.any(Function) });
});
});
describe('data last', function () {
test('it should pick props', function () {
var result = pipe({ a: 1, b: 2, c: 3, d: 4 }, pick(['a', 'd']));
expect(result).toEqual({ a: 1, d: 4 });
});
});