Sha256: 58e084903637590787bcce4977eb58fe4b162337e5c3c0cf6281c364bbfb4483

Contents?: true

Size: 1.28 KB

Versions: 29

Compression:

Stored size: 1.28 KB

Contents

"use strict";

var assert          = require("chai").assert
  , handleException = require("../../lib/resolve-exception");

describe("lib/handle-exception", function () {
	it("Should throw TypeError", function () {
		try {
			handleException(12, "Invalid value");
			throw new Error("Unexpected");
		} catch (error) {
			assert.equal(error.name, "TypeError");
			assert.equal(error.message, "Invalid value");
		}
	});
	it("Should resolve value in default message", function () {
		try {
			handleException(12, "%v is invalid", {});
			throw new Error("Unexpected");
		} catch (error) {
			assert.equal(error.message, "12 is invalid");
		}
	});
	it("Should support optional values via inputOptions.isOptional", function () {
		assert.equal(handleException(null, "%v is invalid", { isOptional: true }, null));
	});
	it("Should support optional values via inputOptions.default", function () {
		// prettier-ignore
		assert.equal(handleException(null, "%v is invalid", { "default": "bar" }), "bar");
	});
	it("Should support custome error message via inputOptions.errorMessage", function () {
		try {
			handleException(null, "%v is invalid", { errorMessage: "%v is not supported age" });
			throw new Error("Unexpected");
		} catch (error) {
			assert.equal(error.message, "null is not supported age");
		}
	});
});

Version data entries

29 entries across 29 versions & 2 rubygems

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