Sha256: 6d533dbcccaefc2b44c059a063462f8a4b385b0cf6b0247b68a35da83bde0bf1

Contents?: true

Size: 1.53 KB

Versions: 30

Compression:

Stored size: 1.53 KB

Contents

"use strict";

var assert        = require("chai").assert
  , toShortString = require("../../lib/to-short-string");

describe("lib/to-short-string", function () {
	it("Should return input string", function () { assert.equal(toShortString("foo"), "foo"); });
	it("Should coerce numbers", function () { assert.equal(toShortString(12), "12"); });
	it("Should coerce booleans", function () { assert.equal(toShortString(true), "true"); });
	it("Should coerce string objects", function () {
		assert.equal(toShortString(new String("bar")), "bar");
	});
	it("Should coerce objects", function () {
		assert.equal(
			toShortString({ toString: function () { return "Some object"; } }), "Some object"
		);
	});
	it("Should coerce null", function () { assert.equal(toShortString(null), "null"); });
	it("Should coerce undefined", function () {
		assert.equal(toShortString(undefined), "undefined");
	});

	if (typeof Symbol === "function") {
		it("Should coerce symbols", function () {
			// eslint-disable-next-line no-undef
			assert.equal(toShortString(Symbol()), "Symbol()");
		});
	}
	it("Should return replacement non coercible values", function () {
		assert.equal(toShortString({ toString: null }), "<Non-coercible to string value>");
	});

	it("Should replace new line characters", function () {
		assert.equal(toShortString("foo\n\r\u2028\u2029bar"), "foo\\n\\r\\u2028\\u2029bar");
	});
	it("Should truncate long string", function () {
		var str = Math.random().toString(36);
		while (str.length < 200) str += str;
		assert.equal(toShortString(str).length, 100);
	});
});

Version data entries

30 entries across 29 versions & 2 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/ext/node_modules/type/test/lib/to-short-string.js
optimacms-0.1.61 spec/dummy/node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-18.0.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.21.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.20.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.19.1 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.19.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.18.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.17.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.16.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.15.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.14.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.13.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.12.2 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.12.1 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.12.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.11.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.10.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.9.0 node_modules/type/test/lib/to-short-string.js
govuk_publishing_components-17.8.0 node_modules/type/test/lib/to-short-string.js