You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
3.5 KiB
63 lines
3.5 KiB
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.configureHostComponentNamesIfNeeded = configureHostComponentNamesIfNeeded;
|
|
exports.getHostComponentNames = getHostComponentNames;
|
|
var React = _interopRequireWildcard(require("react"));
|
|
var _reactNative = require("react-native");
|
|
var _config = require("../config");
|
|
var _renderAct = require("../render-act");
|
|
var _within = require("../within");
|
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
const userConfigErrorMessage = `There seems to be an issue with your configuration that prevents React Native Testing Library from working correctly.
|
|
Please check if you are using compatible versions of React Native and React Native Testing Library.`;
|
|
function getHostComponentNames() {
|
|
let hostComponentNames = (0, _config.getConfig)().hostComponentNames;
|
|
if (!hostComponentNames) {
|
|
hostComponentNames = detectHostComponentNames();
|
|
(0, _config.configureInternal)({
|
|
hostComponentNames
|
|
});
|
|
}
|
|
return hostComponentNames;
|
|
}
|
|
function configureHostComponentNamesIfNeeded() {
|
|
const configHostComponentNames = (0, _config.getConfig)().hostComponentNames;
|
|
if (configHostComponentNames) {
|
|
return;
|
|
}
|
|
const hostComponentNames = detectHostComponentNames();
|
|
(0, _config.configureInternal)({
|
|
hostComponentNames
|
|
});
|
|
}
|
|
function detectHostComponentNames() {
|
|
try {
|
|
const renderer = (0, _renderAct.renderWithAct)( /*#__PURE__*/React.createElement(_reactNative.View, null, /*#__PURE__*/React.createElement(_reactNative.Text, {
|
|
testID: "text"
|
|
}, "Hello"), /*#__PURE__*/React.createElement(_reactNative.TextInput, {
|
|
testID: "textInput"
|
|
})));
|
|
const {
|
|
getByTestId
|
|
} = (0, _within.getQueriesForElement)(renderer.root);
|
|
const textHostName = getByTestId('text').type;
|
|
const textInputHostName = getByTestId('textInput').type;
|
|
|
|
// This code path should not happen as getByTestId always returns host elements.
|
|
if (typeof textHostName !== 'string' || typeof textInputHostName !== 'string') {
|
|
throw new Error('getByTestId returned non-host component');
|
|
}
|
|
return {
|
|
text: textHostName,
|
|
textInput: textInputHostName
|
|
};
|
|
} catch (error) {
|
|
const errorMessage = error && typeof error === 'object' && 'message' in error ? error.message : null;
|
|
throw new Error(`Trying to detect host component names triggered the following error:\n\n${errorMessage}\n\n${userConfigErrorMessage}`);
|
|
}
|
|
}
|
|
//# sourceMappingURL=host-component-names.js.map
|