@sap_oss/wdio-qmate-service
Version:
[](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[](http
113 lines • 4.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Assertion = void 0;
const verboseLogger_1 = require("../../helper/verboseLogger");
/**
* @class assertion
* @memberof common
*/
class Assertion {
vlf = new verboseLogger_1.VerboseLoggerFactory("common", "assertion");
/**
* @function expectEqual
* @memberOf common.assertion
* @description Expects the passed values to be equal.
* @param {Any} value1 - Value (1) to be equal to value (2)
* @param {Any} value2 - Value (2) to be equal to value (1)
* @example common.assertion.expectEqual(value1, value2);
*/
expectEqual(value1, value2) {
const vl = this.vlf.initLog(this.expectEqual);
vl.log(`Expecting ${value1} to be equal to ${value2}`);
expect(value1).toEqual(value2);
}
/**
* @function expectUnequal
* @memberOf common.assertion
* @description Expects the passed values to be unequal.
* @param {Any} value1 - Value (1) to be unequal to value (2)
* @param {Any} value2 - Value (2) to be unequal to value (1)
* @example common.assertion.expectUnequal(value1, value2);
*/
expectUnequal(value1, value2) {
const vl = this.vlf.initLog(this.expectUnequal);
vl.log(`Expecting ${value1} not to be equal to ${value2}`);
expect(value1).not.toEqual(value2);
}
/**
* @function expectTrue
* @memberOf common.assertion
* @description Expects the passed value to be true.
* @param {Any} value - Value to be equal to true
* @example common.assertion.expectTrue(value);
*/
expectTrue(value) {
const vl = this.vlf.initLog(this.expectUnequal);
vl.log(`Expecting ${value} to be true`);
this.expectEqual(value, true);
}
/**
* @function expectFalse
* @memberOf common.assertion
* @description Expects the passed value to be false.
* @param {Boolean} value - The value to be false.
* @example common.assertion.expectFalse(false);
*/
expectFalse(value) {
const vl = this.vlf.initLog(this.expectFalse);
vl.log(`Expecting ${value} to be false`);
this.expectEqual(value, false);
}
/**
* @function expectDefined
* @memberOf common.assertion
* @description Expects the passed values is defined.
* @param {Any} value - Value to be defined (not undefined)
* @example common.assertion.expectDefined(value);
*/
expectDefined(value) {
const vl = this.vlf.initLog(this.expectDefined);
vl.log(`Expecting ${value} to be defined`);
expect(value).toBeDefined();
}
/**
* @function expectUndefined
* @memberOf common.assertion
* @description Expects the passed values is undefined.
* @param {Any} value - Value to be undefined
* @example common.assertion.expectUndefined(value);
*/
expectUndefined(value) {
const vl = this.vlf.initLog(this.expectUndefined);
vl.log(`Expecting ${value} to be undefined`);
expect(value).toBeUndefined();
}
/**
* @function expectUrlToBe
* @memberOf common.assertion
* @description Expects the url to be the passed value.
* @example await common.assertion.expectUrlToBe("www.sap.com");
*/
expectUrlToBe(urlExp) {
const vl = this.vlf.initLog(this.expectUrlToBe);
vl.log(`Expecting current url to be to be ${urlExp}`);
return expect(browser.getUrl()).resolves.toBe(urlExp);
}
/**
* @function expectToContain
* @memberOf common.assertion
* @description Expects the first passed value to contain the second passed value, after normalizing whitespace.
* @param {string} value1 - The string expected to contain value2.
* @param {string} value2 - The string expected to be found within value1.
* @example await common.assertion.expectToContain("foo bar baz", "bar");
*/
expectToContain(value1, value2) {
const vl = this.vlf.initLog(this.expectToContain);
vl.log(`Expecting ${value1} to contain ${value2}`);
const normalizeString = (str) => (str ?? "").replace(/\s+/g, " ").trim();
expect(normalizeString(value1)).toContain(normalizeString(value2));
}
}
exports.Assertion = Assertion;
exports.default = new Assertion();
//# sourceMappingURL=assertion.js.map