chai-string
Advanced tools
Comparing version 1.1.4 to 1.1.6
@@ -73,2 +73,6 @@ (function (plugin) { | ||
chai.string.indexOf = function(str, substr, index) { | ||
return str.indexOf(substr) === index; | ||
}; | ||
var startsWithMethodWrapper = function (expected) { | ||
@@ -160,2 +164,12 @@ var actual = this._obj; | ||
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 | ||
); | ||
}); | ||
// Asserts | ||
@@ -224,2 +238,6 @@ var assert = chai.assert; | ||
assert.indexOf = function(str, substr, index, msg) { | ||
new chai.Assertion(str, msg).to.have.indexOf(substr, index); | ||
} | ||
})); |
{ | ||
"name": "chai-string", | ||
"version": "1.1.4", | ||
"version": "1.1.6", | ||
"keywords": ["chai", "testing", "string", "chai-plugin", "browser"], | ||
@@ -20,9 +20,9 @@ "description": "strings comparison matchers for chai", | ||
"devDependencies": { | ||
"chai": "^1.9.1", | ||
"mocha": "~1.6.0", | ||
"nodemon": "~0.6.23" | ||
"chai": ">=1.9.1", | ||
"mocha": ">=1.6.0", | ||
"nodemon": ">=0.6.23" | ||
}, | ||
"dependencies": { | ||
"chai": "^1.9.1" | ||
"peerDependencies": { | ||
"chai": ">=1.9.1" | ||
} | ||
} |
@@ -34,2 +34,3 @@ # chai-string | ||
* entriesCount | ||
* indexOf | ||
@@ -97,4 +98,10 @@ All assertions are defined for both the BDD and TDD syntax but some aliases exist to make the assertions look good with both styles. | ||
### indexOf | ||
```javascript | ||
assert.indexOf('abcabd', 'ab', 0); | ||
expect('abcabd').to.have.indexOf('ab', 0); | ||
``` | ||
## Thanks | ||
Thanks to the [chai-datetime](https://github.com/gaslight/chai-datetime) module for giving me an idea for how to structure and test a chai plugin. |
@@ -235,2 +235,35 @@ (function (test) { | ||
describe('#indexOf', function() { | ||
it('should return true', function() { | ||
var str = 'abcabd', | ||
substr = 'ab', | ||
index = 0; | ||
chai.string.indexOf(str, substr, index).should.be.true; | ||
}); | ||
it('should return true (2)', function() { | ||
var str = 'abcabd', | ||
substr = 'ca', | ||
index = 2; | ||
chai.string.indexOf(str, substr, index).should.be.true; | ||
}); | ||
it('should return true (3)', function() { | ||
var str = 'ababab', | ||
substr = 'ba', | ||
index = 1; | ||
chai.string.indexOf(str, substr, index).should.be.true; | ||
}); | ||
it('should return false', function() { | ||
var str = 'abcaab', | ||
substr = 'da', | ||
index = 1; | ||
chai.string.indexOf(str, substr, index).should.be.false; | ||
}); | ||
}); | ||
describe('tdd alias', function () { | ||
@@ -308,4 +341,11 @@ | ||
it('.indexOf', function() { | ||
assert.indexOf('abcabd', 'ab', 0); | ||
assert.indexOf('abcabd', 'ca', 2); | ||
assert.indexOf('ababab', 'ba', 1); | ||
expect('ababab').to.have.indexOf('ba', 1); | ||
}); | ||
}); | ||
}); | ||
})); |
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
79873
462
106
+ Addedassertion-error@2.0.1(transitive)
+ Addedchai@5.1.2(transitive)
+ Addedcheck-error@2.1.1(transitive)
+ Addeddeep-eql@5.0.2(transitive)
+ Addedloupe@3.1.2(transitive)
+ Addedpathval@2.0.0(transitive)
- Removedchai@^1.9.1
- Removedassertion-error@1.0.0(transitive)
- Removedchai@1.10.0(transitive)
- Removeddeep-eql@0.1.3(transitive)
- Removedtype-detect@0.1.1(transitive)