Sha256: 54ec462b186a196db2e9cf5df8c78262572aab62e6a3a283b1aca1d57c32b735

Contents?: true

Size: 1.64 KB

Versions: 46

Compression:

Stored size: 1.64 KB

Contents

/* eslint-disable max-nested-callbacks */

import {
    expect
} from 'chai';
import chalk from 'chalk';
import wrapString from './../src/wrapString';

describe('wrapString', () => {
  context('subject is a plain text string', () => {
    context('subject is lesser than the chunk size', () => {
      it('returns subject in a single chunk', () => {
        expect(wrapString('aaa', 3)).to.deep.equal(['aaa']);
      });
    });
    context('subject is larger than the chunk size', () => {
      it('returns subject sliced into multiple chunks', () => {
        expect(wrapString('aaabbbc', 3)).to.deep.equal(['aaa', 'bbb', 'c']);
      });
    });
    context('a chunk starts with a space', () => {
      it('adjusts chunks to offset the space', () => {
        expect(wrapString('aaa   bbb   ccc', 3)).to.deep.equal(['aaa', 'bbb', 'ccc']);
      });
    });
  });
  context('subject string contains ANSI escape codes', () => {
    describe('subject is lesser than the chunk size', () => {
      it('returns subject in a single chunk', () => {
        expect(wrapString(chalk.red('aaa'), 3)).to.deep.equal([
          '\u001b[31m\u001b[31m\u001b[31m\u001b[31m\u001b[31maaa\u001b[39m'
        ]);
      });
    });
    describe('subject is larger than the chunk size', () => {
      it('returns subject sliced into multiple chunks', () => {
        expect(wrapString(chalk.red('aaabbbc'), 3)).to.deep.equal([
          '\u001b[31m\u001b[31m\u001b[31m\u001b[31m\u001b[31maaa\u001b[39m',
          '\u001b[31m\u001b[31m\u001b[31m\u001b[31m\u001b[31mbbb\u001b[39m',
          '\u001b[31m\u001b[31m\u001b[31m\u001b[31m\u001b[31mc\u001b[39m'
        ]);
      });
    });
  });
});

Version data entries

46 entries across 46 versions & 3 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.21.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.20.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.19.1 node_modules/table/test/wrapString.js
govuk_publishing_components-17.19.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.18.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.17.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.16.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.15.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.14.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.13.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.12.2 node_modules/table/test/wrapString.js
govuk_publishing_components-17.12.1 node_modules/table/test/wrapString.js
govuk_publishing_components-17.12.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.11.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.10.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.9.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.8.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.7.0 node_modules/table/test/wrapString.js
govuk_publishing_components-17.6.1 node_modules/table/test/wrapString.js