JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 484619
  • Score
    100M100P100Q173534F
  • License MIT

strings comparison matchers for chai

Package Exports

  • chai-string
  • chai-string/chai-string.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (chai-string) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

chai-string

Matchers for chai to help with common string comparison assertions.

CI Downloads

Usage

const chai = require('chai');
chai.use(require('chai-string'));

Assertions

  • startsWith / startWith
  • startsWithIgnoreCase / startWithIgnoreCase
  • endsWith / endWith
  • endsWithIgnoreCase / endWithIgnoreCase
  • equalIgnoreCase
  • equalIgnoreSpaces
  • containIgnoreSpaces
  • containIgnoreCase
  • singleLine
  • reverseOf
  • palindrome
  • entriesCount
  • indexOf

All assertions are defined for both the BDD and TDD syntax but some aliases exist to make the assertions look good with both styles.

const d1 = 'abcdef',
    d2 = 'abc';

d1.should.startWith.d2;
expect(d1).to.startsWith(d2);
assert.startsWith(d1, d2);

startsWith / startWith

assert.startsWith('abcdef', 'abc');
expect('abcdef').to.startsWith('abc');
'abcdef'.should.startWith('abc');

startsWithIgnoreCase / startWithIgnoreCase

assert.startsWithIgnoreCase('aBcdef', 'abC');
expect('abCdef').to.startsWithIgnoreCase('Abc');
'Abcdef'.should.startWithIgnoreCase('aBc');

endsWith / endWith

assert.endsWith('abcdef', 'def');
expect('abcdef').to.endsWith('def');
'abcdef'.should.endWith('def');

endsWithIgnoreCase / endWithIgnoreCase

assert.endsWithIgnoreCase('abcdEf', 'deF');
expect('abcDef').to.endsWithIgnoreCase('dEf');
'abcdeF'.should.endWithIgnoreCase('Def');

equalIgnoreCase

assert.equalIgnoreCase('abcdef', 'AbCdEf');
expect('abcdef').to.equalIgnoreCase('AbCdEf');

equalIgnoreSpaces

assert.equalIgnoreSpaces('abcdef', 'a\nb\tc\r d  ef');
expect('abcdef').to.equalIgnoreSpaces('a\nb\tc\r d  ef');

containIgnoreSpaces

assert.containIgnoreSpaces('abcdefgh', 'a\nb\tc\r d  ef');
expect('abcdefgh').to.containIgnoreSpaces('a\nb\tc\r d  ef');

containIgnoreCase

assert.containIgnoreCase('abcdefgh', 'AbcDefGH'); 
expect('abcdefgh').to.containIgnoreCase('AbcDefGH');
'abcdef'.should.containIgnoreCase('cDe');

singleLine

assert.singleLine('abcdef');
expect('abcdef').to.be.singleLine();

reverseOf

assert.reverseOf('abcdef', 'fedcba');
expect('abcdef').to.be.reverseOf('fedcba');

palindrome

assert.palindrome('abccba');
expect('abccba').to.be.palindrome();

entriesCount

assert.entriesCount('abcabd', 'ab', 2);
expect('abcabd').to.have.entriesCount('ab', 2);

indexOf

assert.indexOf('abcabd', 'ab', 0);
expect('abcabd').to.have.indexOf('ab', 0);