@aricma/itemids
Version:
Be faster in creating and updating react state, with the ItemIds object.
82 lines (73 loc) • 3.49 kB
JavaScript
;
var _connectors = require("./connectors");
var ERRORS = _interopRequireWildcard(require("../errors"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
// errors
describe("Function Factories Array", () => {
describe("_with", () => {
test("is a function", () => {
expect(typeof _connectors._with).toBe("function");
});
test("returns undefined per default", () => {
expect((0, _connectors._with)()).toBeUndefined();
});
test("is passing on the given object", () => {
const object = [];
expect((0, _connectors._with)(object)).toBe(object);
});
test("is adding the key, value pair to the given object", () => {
const object = [];
const key = "key";
const value = "value";
const result = (0, _connectors._with)(object, key, value);
expect(result.key).toBe(value);
});
test("throws if given value is a function", () => {
expect(() => (0, _connectors._with)([], "add", function () {})).toThrow(ERRORS.utils._with.gotFunction);
});
test("the property attached to the given object is not enumerable and read only", () => {
const object = [];
(0, _connectors._with)(object, "key", "value");
expect(object).toEqual([]);
expect(object.key).toBe("value");
expect(() => {
object["key"] = "FooBar";
}).toThrow();
});
});
describe("_can", () => {
test("is a function", () => {
expect(typeof _connectors._can).toBe("function");
});
test("returns undefined per default", () => {
expect((0, _connectors._can)()).toBeUndefined();
});
test("is passing on the given object", () => {
const object = [];
expect((0, _connectors._can)(object)).toBe(object);
});
test("is adding the given key, function pair to the given object", () => {
const object = [];
const key = "func";
const func = function () {};
const result = (0, _connectors._can)(object, key, func);
expect(result.func).toBe(func);
});
test("throws if given function is No function", () => {
expect(() => (0, _connectors._can)([], "key", "value")).toThrow(ERRORS.utils._can.gotNoFunction);
});
test("the function attached to the given object is not enumerable and read only", () => {
const object = [];
function func(a, b) {
return a + b;
}
(0, _connectors._can)(object, "add", func);
expect(object).toEqual([]);
expect(object.add(1, 2)).toBe(3);
expect(() => {
object["add"] = "FooBar";
}).toThrow();
});
});
});