Add tests for route_config, but needs more assertions.

pull/695/head
Rick Carlino 2018-03-04 11:06:16 -06:00
parent ca5a0c6b82
commit 9e73fcecb8
2 changed files with 15 additions and 6 deletions

View File

@ -1,7 +1,16 @@
import { topLevelRoutes } from "./route_config";
jest.mock("fastclick", () => ({ attach: jest.fn() }));
import { topLevelRoutes } from "../route_config";
const cb = jest.fn(() => {
console.log("TADA!");
});
describe("route configs", () => {
it("generates all of them", () => {
topLevelRoutes
it("generates all of them", async () => {
const routes = topLevelRoutes.childRoutes;
const results = await Promise.all(routes.map(route => route.getComponent(undefined, cb)));
console.log("IMPROVE THESE TESTS THEY ARE NOT GOOD RIGHT NOW");
expect(cb).toHaveBeenCalled();
});
});

View File

@ -15,9 +15,9 @@ function page(path: string, getter: () => Promise<React.ReactType>) {
return {
path,
getComponent(_: void, cb: Function) {
getter()
.then(component => cb(undefined, component))
.catch((e: object) => cb(undefined, crashPage(e)));
const ok = (component: React.ReactType) => cb(undefined, component);
const no = (e: object) => cb(undefined, crashPage(e));
return getter().then(ok, no);
}
};
}