diff --git a/index.js b/index.js index 04d8371..88beaf8 100644 --- a/index.js +++ b/index.js @@ -236,6 +236,19 @@ return this; }; + /** + * Checks if the string equals another case insensitively. + */ + + Assertion.prototype.equalCaseInsensitive = function (obj) { + this.assert( + expect.equalCaseInsensitive(this.obj, obj) + , function(){ return 'expected ' + i(this.obj) + ' to be equal case insensitively ' + i(obj) } + , function(){ return 'expected ' + i(this.obj) + ' to be not equal case insensitively ' + i(obj) } + , obj); + return this; + }; + /** * Assert within start to finish (inclusive). * @@ -910,6 +923,26 @@ } }; + /** + * Asserts strings equality case-insensitive + */ + + expect.equalCaseInsensitive = function equalCaseInsensitive(actual, expected) { + // check if values are string + if (typeof actual != "string" && typeof expected != "string"){ + throw new Error(`values are not string, actual value is a ${typeof actual} and expected value is a ${typeof expected}`); + } else if (typeof actual != "string"){ + throw new Error(`actual value is not string, it's a ${typeof actual}`); + } else if (typeof expected != "string"){ + throw new Error(`expected value is not string, it's a ${typeof expected}`); + } + + // check values equality case-insensitive + const lowerCaseActual = actual.toLowerCase(); + const lowerCaseExpected = expected.toLowerCase(); + return lowerCaseActual === lowerCaseExpected; + }; + function isUndefinedOrNull (value) { return value === null || value === undefined; }