UNPKG

react-obsidian

Version:

Dependency injection framework for React and React Native applications

29 lines 1.35 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.mockGraphs = void 0; const ObjectGraph_1 = require("../src/graph/ObjectGraph"); const GraphMiddleware_1 = require("../src/graph/registry/GraphMiddleware"); const GraphRegistry_1 = __importDefault(require("../src/graph/registry/GraphRegistry")); function mockGraphs(graphNameToGraph) { const graphMiddleware = new class extends GraphMiddleware_1.GraphMiddleware { resolve(resolveChain, Graph, props) { if (graphNameToGraph[Graph.name]) { const GraphOrGenerator = graphNameToGraph[Graph.name]; return (0, ObjectGraph_1.isGraph)(GraphOrGenerator) ? new GraphOrGenerator(props) : GraphOrGenerator(props); } return resolveChain.proceed(Graph, props); } }(); clearRegisteredGraphs(graphNameToGraph); GraphRegistry_1.default.addGraphMiddleware(graphMiddleware); } exports.mockGraphs = mockGraphs; function clearRegisteredGraphs(graphNameToGraph) { for (const graphName of Object.keys(graphNameToGraph)) { GraphRegistry_1.default.clearGraphAfterItWasMockedInTests(graphName); } } //# sourceMappingURL=mockGraphs.js.map