chai-string
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -60,3 +60,10 @@ (function (plugin) { | ||
chai.string.singleLine = function(str) { | ||
chai.string.containIgnoreCase = function (str1, str2) { | ||
if (!isString(str1) || !isString(str2)) { | ||
return false; | ||
} | ||
return str1.toLowerCase().indexOf(str2.toLowerCase()) > -1; | ||
} | ||
chai.string.singleLine = function (str) { | ||
if (!isString(str)) { | ||
@@ -68,3 +75,3 @@ return false; | ||
chai.string.reverseOf = function(str, reversed) { | ||
chai.string.reverseOf = function (str, reversed) { | ||
if (!isString(str) || !isString(reversed)) { | ||
@@ -76,3 +83,3 @@ return false; | ||
chai.string.palindrome = function(str) { | ||
chai.string.palindrome = function (str) { | ||
if (!isString(str)) { | ||
@@ -82,3 +89,3 @@ return false; | ||
var len = str.length; | ||
for ( var i = 0; i < Math.floor(len/2); i++ ) { | ||
for (var i = 0; i < Math.floor(len / 2); i++) { | ||
if (str[i] !== str[len - 1 - i]) { | ||
@@ -91,3 +98,3 @@ return false; | ||
chai.string.entriesCount = function(str, substr, count) { | ||
chai.string.entriesCount = function (str, substr, count) { | ||
var matches = 0; | ||
@@ -111,3 +118,3 @@ if (isString(str) && isString(substr)) { | ||
chai.string.indexOf = function(str, substr, index) { | ||
chai.string.indexOf = function (str, substr, index) { | ||
var indx = !isString(str) || !isString(substr) ? -1 : str.indexOf(substr); | ||
@@ -173,2 +180,12 @@ return indx === index; | ||
chai.Assertion.addChainableMethod('containIgnoreCase', function (expected) { | ||
var actual = this._obj; | ||
return this.assert( | ||
chai.string.containIgnoreCase(actual, expected), | ||
'expected ' + this._obj + ' to contain ' + expected + ' ignoring case', | ||
'expected ' + this._obj + ' not to contain ' + expected + ' ignoring case' | ||
); | ||
}); | ||
chai.Assertion.addChainableMethod('singleLine', function () { | ||
@@ -184,3 +201,3 @@ var actual = this._obj; | ||
chai.Assertion.addChainableMethod('reverseOf', function(expected) { | ||
chai.Assertion.addChainableMethod('reverseOf', function (expected) { | ||
var actual = this._obj; | ||
@@ -205,3 +222,3 @@ | ||
chai.Assertion.addChainableMethod('entriesCount', function(substr, expected) { | ||
chai.Assertion.addChainableMethod('entriesCount', function (substr, expected) { | ||
var actual = this._obj; | ||
@@ -216,9 +233,9 @@ | ||
chai.Assertion.addChainableMethod('indexOf', function(substr, index) { | ||
chai.Assertion.addChainableMethod('indexOf', function (substr, index) { | ||
var actual = this._obj; | ||
return this.assert( | ||
chai.string.indexOf(actual, substr, index), | ||
'expected ' + this._obj + ' to have ' + substr + ' on index ' + index, | ||
'expected ' + this._obj + ' to not have ' + substr + ' on index ' + index | ||
chai.string.indexOf(actual, substr, index), | ||
'expected ' + this._obj + ' to have ' + substr + ' on index ' + index, | ||
'expected ' + this._obj + ' to not have ' + substr + ' on index ' + index | ||
); | ||
@@ -270,31 +287,39 @@ }); | ||
assert.singleLine = function(val, exp, msg) { | ||
assert.containIgnoreCase = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.be.containIgnoreCase(exp); | ||
}; | ||
assert.notContainIgnoreCase = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.not.be.containIgnoreCase(exp); | ||
}; | ||
assert.singleLine = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.be.singleLine(); | ||
}; | ||
assert.notSingleLine = function(val, exp, msg) { | ||
assert.notSingleLine = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.not.be.singleLine(); | ||
}; | ||
assert.reverseOf = function(val, exp, msg) { | ||
assert.reverseOf = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.be.reverseOf(exp); | ||
}; | ||
assert.notReverseOf = function(val, exp, msg) { | ||
assert.notReverseOf = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.not.be.reverseOf(exp); | ||
}; | ||
assert.palindrome = function(val, exp, msg) { | ||
assert.palindrome = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.be.palindrome(); | ||
}; | ||
assert.notPalindrome = function(val, exp, msg) { | ||
assert.notPalindrome = function (val, exp, msg) { | ||
new chai.Assertion(val, msg).to.not.be.palindrome(); | ||
}; | ||
assert.entriesCount = function(str, substr, count, msg) { | ||
assert.entriesCount = function (str, substr, count, msg) { | ||
new chai.Assertion(str, msg).to.have.entriesCount(substr, count); | ||
}; | ||
assert.indexOf = function(str, substr, index, msg) { | ||
assert.indexOf = function (str, substr, index, msg) { | ||
new chai.Assertion(str, msg).to.have.indexOf(substr, index); | ||
@@ -301,0 +326,0 @@ }; |
{ | ||
"name": "chai-string", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"keywords": ["chai", "testing", "string", "chai-plugin", "browser"], | ||
@@ -5,0 +5,0 @@ "description": "strings comparison matchers for chai", |
@@ -80,2 +80,9 @@ # chai-string | ||
### containIgnoreCase | ||
```javascript | ||
assert.containIgnoreCase('abcdefgh', 'AbcDefGH'); | ||
expect('abcdefgh').to.containIgnoreCase('AbcDefGH'); | ||
'abcdef'.should.containIgnoreCase('cDe'); | ||
``` | ||
### singleLine | ||
@@ -82,0 +89,0 @@ ```javascript |
135
test/test.js
(function (test) { | ||
if (typeof require === "function"&& typeof exports === "object"&& typeof module === "object") { | ||
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") { | ||
// NodeJS | ||
@@ -76,3 +76,3 @@ (function () { | ||
it('check that', function () { | ||
var obj = { foo: 'hello world' }; | ||
var obj = {foo: 'hello world'}; | ||
expect(obj).to.have.property('foo').that.startsWith('hello'); | ||
@@ -231,5 +231,42 @@ }); | ||
describe('#singleLine', function() { | ||
describe('#containIgnoreCase', function () { | ||
it('should return true', function() { | ||
it('should return true', function () { | ||
var str1 = 'abcdef', | ||
str2 = 'cDe'; | ||
chai.string.containIgnoreCase(str1, str2).should.be.true; | ||
}); | ||
it('should return true (2)', function () { | ||
'abcdef'.should.containIgnoreCase('cDe'); | ||
}); | ||
it('should return true (3)', function () { | ||
var str1 = 'abcdef', | ||
str2 = 'AbCdeF'; | ||
chai.string.containIgnoreCase(str1, str2).should.be.true; | ||
}); | ||
it('should return false', function () { | ||
var str1 = 'abcdef', | ||
str2 = 'efg'; | ||
chai.string.containIgnoreCase(str1, str2).should.be.false; | ||
}); | ||
it('should return false (2)', function () { | ||
var str1 = '123', | ||
str2 = 123; | ||
chai.string.containIgnoreCase(str1, str2).should.be.false; | ||
}); | ||
it('should return false (3)', function () { | ||
var str1 = 'abcdef', | ||
str2 = 'zabcd'; | ||
chai.string.containIgnoreCase(str1, str2).should.be.false; | ||
}); | ||
}); | ||
describe('#singleLine', function () { | ||
it('should return true', function () { | ||
var str = 'abcdef'; | ||
@@ -239,3 +276,3 @@ chai.string.singleLine(str).should.be.true; | ||
it('should return false', function() { | ||
it('should return false', function () { | ||
var str = "abc\ndef"; | ||
@@ -245,3 +282,3 @@ chai.string.singleLine(str).should.be.false; | ||
it('should return false (2)', function() { | ||
it('should return false (2)', function () { | ||
chai.string.singleLine(12).should.be.false; | ||
@@ -252,3 +289,3 @@ }); | ||
describe('#reverseOf', function() { | ||
describe('#reverseOf', function () { | ||
@@ -277,5 +314,5 @@ it('should return true', function () { | ||
describe('#palindrome', function() { | ||
describe('#palindrome', function () { | ||
it('should return true', function() { | ||
it('should return true', function () { | ||
var str = 'abcba'; | ||
@@ -285,3 +322,3 @@ chai.string.palindrome(str).should.be.true; | ||
it('should return true (2)', function() { | ||
it('should return true (2)', function () { | ||
var str = 'abccba'; | ||
@@ -291,3 +328,3 @@ chai.string.palindrome(str).should.be.true; | ||
it('should return true (3)', function() { | ||
it('should return true (3)', function () { | ||
var str = ''; | ||
@@ -297,3 +334,3 @@ chai.string.palindrome(str).should.be.true; | ||
it('should return false', function() { | ||
it('should return false', function () { | ||
var str = 'abcdef'; | ||
@@ -303,3 +340,3 @@ chai.string.palindrome(str).should.be.false; | ||
it('should return false (2)', function() { | ||
it('should return false (2)', function () { | ||
chai.string.palindrome(12).should.be.false; | ||
@@ -310,5 +347,5 @@ }); | ||
describe('#entriesCount', function() { | ||
describe('#entriesCount', function () { | ||
it('should return true', function() { | ||
it('should return true', function () { | ||
var str = 'abcabd', | ||
@@ -320,3 +357,3 @@ substr = 'ab', | ||
it('should return true (2)', function() { | ||
it('should return true (2)', function () { | ||
var str = 'ababd', | ||
@@ -328,3 +365,3 @@ substr = 'ab', | ||
it('should return true (3)', function() { | ||
it('should return true (3)', function () { | ||
var str = 'abab', | ||
@@ -336,3 +373,3 @@ substr = 'ab', | ||
it('should return true (4)', function() { | ||
it('should return true (4)', function () { | ||
var str = 12, | ||
@@ -344,3 +381,3 @@ substr = 'ab', | ||
it('should return true (5)', function() { | ||
it('should return true (5)', function () { | ||
var str = '12', | ||
@@ -352,3 +389,3 @@ substr = 12, | ||
it('should return false ', function() { | ||
it('should return false ', function () { | ||
var str = '12', | ||
@@ -362,26 +399,26 @@ substr = 12, | ||
describe('#indexOf', function() { | ||
describe('#indexOf', function () { | ||
it('should return true', function() { | ||
it('should return true', function () { | ||
var str = 'abcabd', | ||
substr = 'ab', | ||
index = 0; | ||
substr = 'ab', | ||
index = 0; | ||
chai.string.indexOf(str, substr, index).should.be.true; | ||
}); | ||
it('should return true (2)', function() { | ||
it('should return true (2)', function () { | ||
var str = 'abcabd', | ||
substr = 'ca', | ||
index = 2; | ||
substr = 'ca', | ||
index = 2; | ||
chai.string.indexOf(str, substr, index).should.be.true; | ||
}); | ||
it('should return true (3)', function() { | ||
it('should return true (3)', function () { | ||
var str = 'ababab', | ||
substr = 'ba', | ||
index = 1; | ||
substr = 'ba', | ||
index = 1; | ||
chai.string.indexOf(str, substr, index).should.be.true; | ||
}); | ||
it('should return true (4)', function() { | ||
it('should return true (4)', function () { | ||
var str = '12', | ||
@@ -393,3 +430,3 @@ substr = 12, | ||
it('should return true (5)', function() { | ||
it('should return true (5)', function () { | ||
var str = 12, | ||
@@ -401,10 +438,10 @@ substr = '12', | ||
it('should return false', function() { | ||
it('should return false', function () { | ||
var str = 'abcaab', | ||
substr = 'da', | ||
index = 1; | ||
substr = 'da', | ||
index = 1; | ||
chai.string.indexOf(str, substr, index).should.be.false; | ||
}); | ||
it('should return false (2)', function() { | ||
it('should return false (2)', function () { | ||
var str = '12', | ||
@@ -416,3 +453,3 @@ substr = 12, | ||
it('should return false (3)', function() { | ||
it('should return false (3)', function () { | ||
var str = 12, | ||
@@ -498,31 +535,31 @@ substr = '12', | ||
it('.singleLine', function() { | ||
it('.singleLine', function () { | ||
assert.singleLine(this.str); | ||
}); | ||
it('.notSingleLine', function() { | ||
it('.notSingleLine', function () { | ||
assert.notSingleLine("abc\ndef"); | ||
}); | ||
it('.notSingleLine (2)', function() { | ||
it('.notSingleLine (2)', function () { | ||
assert.notSingleLine(12); | ||
}); | ||
it('.reverseOf', function() { | ||
it('.reverseOf', function () { | ||
assert.reverseOf(this.str, 'fedcba'); | ||
}); | ||
it('.notReverseOf', function() { | ||
it('.notReverseOf', function () { | ||
assert.notReverseOf(this.str, 'aaaaa'); | ||
}); | ||
it('.notReverseOf (2)', function() { | ||
it('.notReverseOf (2)', function () { | ||
assert.notReverseOf('12', 12); | ||
}); | ||
it('.notReverseOf (3)', function() { | ||
it('.notReverseOf (3)', function () { | ||
assert.notReverseOf(12, '12'); | ||
}); | ||
it('.palindrome', function() { | ||
it('.palindrome', function () { | ||
assert.palindrome('abcba'); | ||
@@ -533,11 +570,11 @@ assert.palindrome('abccba'); | ||
it('.notPalindrome', function() { | ||
it('.notPalindrome', function () { | ||
assert.notPalindrome(this.str); | ||
}); | ||
it('.notPalindrome (2)', function() { | ||
it('.notPalindrome (2)', function () { | ||
assert.notPalindrome(12); | ||
}); | ||
it('.entriesCount', function() { | ||
it('.entriesCount', function () { | ||
assert.entriesCount('abcabd', 'ab', 2); | ||
@@ -551,3 +588,3 @@ assert.entriesCount('ababd', 'ab', 2); | ||
it('.indexOf', function() { | ||
it('.indexOf', function () { | ||
assert.indexOf('abcabd', 'ab', 0); | ||
@@ -554,0 +591,0 @@ assert.indexOf('abcabd', 'ca', 2); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31324
714
120