-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
/* global it, expect, describe */ | ||
|
||
import { ParseErr } from "../src/err"; | ||
import path from "path"; | ||
import { Eta } from "../src/index"; | ||
|
||
describe("ParseErr", () => { | ||
it("error throws correctly", () => { | ||
const eta = new Eta(); | ||
|
||
it("error while parsing", () => { | ||
try { | ||
ParseErr("Something Unexpected Happened!", "template {{", 9); | ||
eta.renderString("template <%", {}); | ||
} catch (ex) { | ||
expect((ex as Error).name).toBe("Eta Error"); | ||
expect((ex as Error).message).toBe(`Something Unexpected Happened! at line 1 col 10: | ||
expect((ex as Error).message).toBe(`unclosed tag at line 1 col 10: | ||
template {{ | ||
template <% | ||
^`); | ||
expect(ex instanceof Error).toBe(true); | ||
} | ||
}); | ||
it("error throws without Object.setPrototypeOf", () => { | ||
Object.defineProperty(Object, "setPrototypeOf", { value: undefined }); | ||
}); | ||
|
||
describe("RuntimeErr", () => { | ||
const eta = new Eta({ debug: true, views: path.join(__dirname, "templates") }); | ||
|
||
const errorFilepath = path.join(__dirname, "templates/runtime-error.eta"); | ||
|
||
it("error throws correctly", () => { | ||
try { | ||
ParseErr("Something Unexpected Happened!", "template {{", 9); | ||
eta.render("./runtime-error", {}); | ||
} catch (ex) { | ||
expect((ex as Error).name).toBe("Eta Error"); | ||
expect((ex as Error).message).toBe(`Something Unexpected Happened! at line 1 col 10: | ||
expect((ex as Error).name).toBe("ReferenceError"); | ||
expect((ex as Error).message).toBe(`${errorFilepath}:2 | ||
1| | ||
>> 2| <%= undefinedVariable %> | ||
3| Lorem Ipsum | ||
template {{ | ||
^`); | ||
expect(ex instanceof Error).toBe(true); | ||
undefinedVariable is not defined`); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
<%= undefinedVariable %> | ||
Lorem Ipsum |