Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test coverage for EleventyErrorUtil #753

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions test/EleventyErrorUtilTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import test from "ava";
import EleventyErrorUtil from "../src/EleventyErrorUtil";

const SAMPLE_ERROR = new Error("Nothing to see here");

const {
cleanMessage,
hasEmbeddedError,
convertErrorToString,
deconvertErrorToObject
} = EleventyErrorUtil;

test("hasEmbeddedError()", t => {
t.false(hasEmbeddedError(""));
t.true(hasEmbeddedError(convertErrorToString(SAMPLE_ERROR)));
});

test("cleanMessage()", t => {
const text = "I am the very model of a sample text input";
t.is(cleanMessage(text), text);
t.is(cleanMessage(text + convertErrorToString(SAMPLE_ERROR)), text);
});

test("deconvertErrorToObject() should throw on invalid inputs", t => {
t.throws(
() => deconvertErrorToObject(undefined),
"Could not convert error object from: undefined"
);
t.throws(
() => deconvertErrorToObject(""),
"Could not convert error object from: "
);
t.throws(
() => deconvertErrorToObject("Not an error"),
"Could not convert error object from: Not an error"
);
});

test("deconvertErrorToObject() should return its argument if it does not contain another error", t => {
t.is(deconvertErrorToObject(SAMPLE_ERROR), SAMPLE_ERROR);
});

test("deconvertErrorToObject() should get message and stack from convertErrorToString()", t => {
const nestingError = new Error(
"This error contains a sample error: " + convertErrorToString(SAMPLE_ERROR)
);
const result = deconvertErrorToObject(nestingError);
t.is(result.name, nestingError.name);
t.is(result.message, SAMPLE_ERROR.message);
t.is(result.stack, SAMPLE_ERROR.stack);
});