Files
cellxgene/client/__tests__/util/nameCreators.test.js
Bruce Martin 2616b5c185 finish tests for world (#340)
* Create Release_Validation_Recipe.md

* nameCreators test and better error handling

* add test for createObsDimensionMap

* add last set of tests for world module
2018-10-18 09:54:57 -07:00

69 lines
1.9 KiB
JavaScript

/*
Test cases for nameCreators.js.
*/
import {
layoutDimensionName,
obsAnnoDimensionName,
diffexpDimensionName,
userDefinedDimensionName,
makeContinuousDimensionName
} from "../../src/util/nameCreators";
describe("nameCreators", () => {
const nameCreators = [
layoutDimensionName,
obsAnnoDimensionName,
diffexpDimensionName,
userDefinedDimensionName
];
test("check for namespace isolation", () => {
const foo = "foo";
nameCreators.forEach(fn => expect(fn(foo)).not.toBe(foo));
const bar = "bar";
nameCreators.forEach(fn => expect(fn(foo)).not.toBe(fn(bar)));
nameCreators.forEach(fn => {
const allOtherFn = nameCreators.filter(elmnt => elmnt !== fn);
allOtherFn.forEach(otherFn => expect(fn(foo)).not.toBe(otherFn(foo)));
});
});
test("check for legal keys", () => {
/* need namespace creators to return strings only */
nameCreators.forEach(fn => expect(fn("X")).toMatch(/X/));
});
});
describe("makeContinuousDimensionName", () => {
test("namespaces", () => {
expect(makeContinuousDimensionName({ isObs: true }, "OK")).toMatch(/OK/);
expect(makeContinuousDimensionName({ isDiffExp: true }, "OK")).toMatch(
/OK/
);
expect(makeContinuousDimensionName({ isUserDefined: true }, "OK")).toMatch(
/OK/
);
});
test("error handling", () => {
expect(() => makeContinuousDimensionName({}, "oops")).toThrow();
expect(() =>
makeContinuousDimensionName(
{ isObs: false, isDiffExp: false, isUserDefined: false },
"oops"
)
).toThrow();
expect(() =>
makeContinuousDimensionName({ isObs: true }, "OK")
).not.toThrow();
expect(() =>
makeContinuousDimensionName({ isDiffExp: true }, "OK")
).not.toThrow();
expect(() =>
makeContinuousDimensionName({ isUserDefined: true }, "OK")
).not.toThrow();
});
});