Sha256: 658f923c6ecb5c5762de7a7a98809525ce084421fe5d600ecf6176e154d92782

Contents?: true

Size: 1.17 KB

Versions: 30

Compression:

Stored size: 1.17 KB

Contents

"use strict";

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

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

	if (typeof Symbol === "function") {
		it("Should coerce symbols", function () {
			// eslint-disable-next-line no-undef
			assert.equal(safeToString(Symbol()), "Symbol()");
		});
	}
	it("Should return null for non coercible values", function () {
		assert.equal(safeToString({ toString: null }), null);
	});
});

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/safe-to-string.js
optimacms-0.1.61 spec/dummy/node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-18.0.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.21.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.20.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.19.1 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.19.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.18.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.17.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.16.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.15.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.14.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.13.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.12.2 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.12.1 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.12.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.11.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.10.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.9.0 node_modules/type/test/lib/safe-to-string.js
govuk_publishing_components-17.8.0 node_modules/type/test/lib/safe-to-string.js