detox-allure2-adapter
Version:
Detox adapter for jest-allure2-reporter
43 lines • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatExpectation = exports.formatWhileCondition = void 0;
const utils_1 = require("../../utils");
const predicate_formatters_1 = require("./predicate-formatters");
const formatExpectationVerb = (invocation) => {
const hasNot = invocation.modifiers?.includes('not');
const verb = invocation
.expectation.replace(/([A-Z])/g, ' $1')
.toLowerCase()
.trim();
return `${hasNot ? 'not ' : ''}${verb}`;
};
const formatExpectationParams = (invocation) => {
if (!Array.isArray(invocation.params)) {
return null;
}
const [expected] = invocation.params;
switch (invocation.expectation) {
case 'toBeVisible': {
return typeof expected === 'number'
? (0, utils_1.msg)(`by ${(0, utils_1.percentVisible)(expected)}`, { expected })
: null;
}
default: {
return expected == null ? null : (0, utils_1.msg)(`${(0, utils_1.truncate)(expected)}`, { expected });
}
}
};
const formatWhileCondition = (expectation) => {
return expectation
? (0, utils_1.concat)('while waiting for', (0, predicate_formatters_1.formatPredicate)(expectation.predicate, 'while'), formatExpectationVerb(expectation))
: null;
};
exports.formatWhileCondition = formatWhileCondition;
const formatExpectation = (invocation) => {
if (!invocation.expectation) {
return null;
}
return (0, utils_1.concat)('Expect', (0, predicate_formatters_1.formatPredicate)(invocation.predicate), formatExpectationVerb(invocation), formatExpectationParams(invocation));
};
exports.formatExpectation = formatExpectation;
//# sourceMappingURL=expectation-formatters.js.map