mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 11:18:39 +00:00
Invalid input error message (#540)
* Added check for type of expressions passed to parseTree function * Added tests for bad input raising exception * Added test for supported types NOT throwing exception * Added test case for parser taking String objects
This commit is contained in:
committed by
Martin von Gagern
parent
a16ae7a5eb
commit
f1be1a3462
@@ -1382,6 +1382,33 @@ describe("An HTML font tree-builder", function() {
|
||||
span = "<span class=\"mord mathbb\" style=\"color:blue;\">R</span>";
|
||||
expect(markup).toContain(span);
|
||||
});
|
||||
|
||||
it("should throw TypeError when the expression is of the wrong type", function() {
|
||||
expect(function() {
|
||||
katex.renderToString({badInputType: "yes"});
|
||||
}).toThrowError(TypeError);
|
||||
expect(function() {
|
||||
katex.renderToString([1, 2]);
|
||||
}).toThrowError(TypeError);
|
||||
expect(function() {
|
||||
katex.renderToString(undefined);
|
||||
}).toThrowError(TypeError);
|
||||
expect(function() {
|
||||
katex.renderToString(null);
|
||||
}).toThrowError(TypeError);
|
||||
expect(function() {
|
||||
katex.renderToString(1.234);
|
||||
}).toThrowError(TypeError);
|
||||
});
|
||||
|
||||
it("should not throw TypeError when the expression is a supported type", function() {
|
||||
expect(function() {
|
||||
katex.renderToString("\\sqrt{123}");
|
||||
}).not.toThrowError(TypeError);
|
||||
expect(function() {
|
||||
katex.renderToString(new String("\\sqrt{123}"));
|
||||
}).not.toThrowError(TypeError);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1878,3 +1905,15 @@ describe("A macro expander", function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("A parser taking String objects", function() {
|
||||
it("should not fail on an empty String object", function() {
|
||||
expect(new String("")).toParse();
|
||||
});
|
||||
|
||||
it("should parse the same as a regular string", function() {
|
||||
expect(new String("xy")).toParseLike("xy");
|
||||
expect(new String("\\div")).toParseLike("\\div");
|
||||
expect(new String("\\frac 1 2")).toParseLike("\\frac 1 2");
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user