@vtex/styleguide
Version:
> VTEX Styleguide React components ([Docs](https://vtex.github.io/styleguide))
40 lines (29 loc) • 926 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useTestingContext = useTestingContext;
exports.TestingProvider = TestingProvider;
var _react = require("react");
var _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var TestingContext = (0, _react.createContext)(null);
function useTestingContext() {
var context = (0, _react.useContext)(TestingContext);
if (!context) {
throw new Error('Do not use E2ETestable components outside of the TestingContext');
}
return context;
}
function TestingProvider(_ref) {
var testId = _ref.testId,
children = _ref.children;
var value = _react2.default.useMemo(function () {
return {
testId: testId
};
}, [testId]);
return _react2.default.createElement(TestingContext.Provider, {
value: value
}, children);
}