@blac/react
Version:
React bindings for BlaC — useBloc hook with automatic re-render optimization
60 lines (59 loc) • 1.76 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
let _blac_core = require("@blac/core");
let _blac_core_testing = require("@blac/core/testing");
let _testing_library_react = require("@testing-library/react");
//#region src/testing.ts
function renderWithBloc(ui, options) {
const { bloc: BlocClass, args, ...stubOptions } = options;
const previous = (0, _blac_core.getRegistry)();
(0, _blac_core.setRegistry)(new _blac_core.StateContainerRegistry());
const instance = (0, _blac_core_testing.createCubitStub)(BlocClass, {
...stubOptions,
args
});
(0, _blac_core_testing.registerOverride)(BlocClass, instance, args);
let renderResult;
try {
renderResult = (0, _testing_library_react.render)(ui);
} catch (e) {
(0, _blac_core.setRegistry)(previous);
throw e;
}
const originalUnmount = renderResult.unmount;
renderResult.unmount = () => {
originalUnmount();
(0, _blac_core.setRegistry)(previous);
};
return {
...renderResult,
bloc: instance
};
}
function renderWithRegistry(ui, setup) {
const previous = (0, _blac_core.getRegistry)();
const testRegistry = new _blac_core.StateContainerRegistry();
(0, _blac_core.setRegistry)(testRegistry);
try {
setup(testRegistry);
} catch (e) {
(0, _blac_core.setRegistry)(previous);
throw e;
}
let renderResult;
try {
renderResult = (0, _testing_library_react.render)(ui);
} catch (e) {
(0, _blac_core.setRegistry)(previous);
throw e;
}
const originalUnmount = renderResult.unmount;
renderResult.unmount = () => {
originalUnmount();
(0, _blac_core.setRegistry)(previous);
};
return renderResult;
}
//#endregion
exports.renderWithBloc = renderWithBloc;
exports.renderWithRegistry = renderWithRegistry;
//# sourceMappingURL=testing.cjs.map