https://github.com/onechiporenko/chai-string
Strings comparison matchers for chai
https://github.com/onechiporenko/chai-string
chai chai-plugin chai-string javascript
Last synced: 23 days ago
JSON representation
Strings comparison matchers for chai
- Host: GitHub
- URL: https://github.com/onechiporenko/chai-string
- Owner: onechiporenko
- License: mit
- Created: 2014-09-01T11:49:55.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2025-03-26T06:14:05.000Z (about 1 month ago)
- Last Synced: 2025-03-28T21:02:25.097Z (about 1 month ago)
- Topics: chai, chai-plugin, chai-string, javascript
- Language: JavaScript
- Size: 77.1 KB
- Stars: 25
- Watchers: 2
- Forks: 11
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chai-string
Matchers for chai to help with common string comparison assertions.
[](https://github.com/onechiporenko/chai-string/actions/workflows/ci.yml)
[](https://www.npmjs.com/package/chai-string)## Usage
* `[email protected]` is compatible with `[email protected]` and `[email protected]`.
* `[email protected]` is compatible with `[email protected]` because of ESM.All assertions should work in the same way with both versions.
```javascript
// v1.x
const chai = require('chai');
chai.use(require('chai-string'));// v2.x
import { use } from 'chai';
import chaiString from 'chai-string';const chai = use(chaiString);
```## Assertions
* startsWith / startWith
* startsWithIgnoreCase / startWithIgnoreCase
* endsWith / endWith
* endsWithIgnoreCase / endWithIgnoreCase
* equalIgnoreCase
* equalIgnoreSpaces
* containIgnoreSpaces
* containIgnoreCase
* singleLine
* reverseOf
* palindrome
* entriesCount
* indexOfAll assertions are defined for both the BDD and TDD syntax but some aliases exist to make the assertions look good with both styles.
```javascript
const d1 = 'abcdef',
d2 = 'abc';d1.should.startWith.d2;
expect(d1).to.startsWith(d2);
assert.startsWith(d1, d2);
```### startsWith / startWith
```javascript
assert.startsWith('abcdef', 'abc');
expect('abcdef').to.startsWith('abc');
'abcdef'.should.startWith('abc');
```### startsWithIgnoreCase / startWithIgnoreCase
```javascript
assert.startsWithIgnoreCase('aBcdef', 'abC');
expect('abCdef').to.startsWithIgnoreCase('Abc');
'Abcdef'.should.startWithIgnoreCase('aBc');
```### endsWith / endWith
```javascript
assert.endsWith('abcdef', 'def');
expect('abcdef').to.endsWith('def');
'abcdef'.should.endWith('def');
```### endsWithIgnoreCase / endWithIgnoreCase
```javascript
assert.endsWithIgnoreCase('abcdEf', 'deF');
expect('abcDef').to.endsWithIgnoreCase('dEf');
'abcdeF'.should.endWithIgnoreCase('Def');
```### equalIgnoreCase
```javascript
assert.equalIgnoreCase('abcdef', 'AbCdEf');
expect('abcdef').to.equalIgnoreCase('AbCdEf');
```### equalIgnoreSpaces
```javascript
assert.equalIgnoreSpaces('abcdef', 'a\nb\tc\r d ef');
expect('abcdef').to.equalIgnoreSpaces('a\nb\tc\r d ef');
```### containIgnoreSpaces
```javascript
assert.containIgnoreSpaces('abcdefgh', 'a\nb\tc\r d ef');
expect('abcdefgh').to.containIgnoreSpaces('a\nb\tc\r d ef');
```### containIgnoreCase
```javascript
assert.containIgnoreCase('abcdefgh', 'AbcDefGH');
expect('abcdefgh').to.containIgnoreCase('AbcDefGH');
'abcdef'.should.containIgnoreCase('cDe');
```### singleLine
```javascript
assert.singleLine('abcdef');
expect('abcdef').to.be.singleLine();
```### reverseOf
```javascript
assert.reverseOf('abcdef', 'fedcba');
expect('abcdef').to.be.reverseOf('fedcba');
```### palindrome
```javascript
assert.palindrome('abccba');
expect('abccba').to.be.palindrome();
```### entriesCount
```javascript
assert.entriesCount('abcabd', 'ab', 2);
expect('abcabd').to.have.entriesCount('ab', 2);
```### indexOf
```javascript
assert.indexOf('abcabd', 'ab', 0);
expect('abcabd').to.have.indexOf('ab', 0);
```