Improve testing

Summary:
Move dom creation into katex.js so our tests can test non-dom things, and add
some buildTree tests. Add some checks make utils.js work in node. Add support
for jasmine-node, to allow for command line unit testing.

Test Plan:
- Make sure tests work, in both the browser and with `make test`
- Make sure huxley screenshots didn't change

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D13125
This commit is contained in:
Emily Eisenberg
2014-09-12 13:30:30 -07:00
parent 5cca3a299e
commit 403dca64ab
8 changed files with 62 additions and 16 deletions

View File

@@ -2,6 +2,15 @@ var buildTree = require("../buildTree");
var parseTree = require("../parseTree");
var ParseError = require("../ParseError");
var getBuilt = function(expr) {
expect(expr).toBuild();
var built = buildTree(parseTree(expr));
// Remove the outer .katex and .katex-inner layers
return built.children[0].children[2].children;
};
beforeEach(function() {
jasmine.addMatchers({
toParse: function() {
@@ -949,3 +958,31 @@ describe("A style change parser", function() {
expect(displayBody[0].value).toMatch("e");
});
});
describe("A bin builder", function() {
it("should create mbins normally", function() {
var built = getBuilt("x + y");
expect(built[1].classes).toContain("mbin");
});
it("should create ords when at the beginning of lists", function() {
var built = getBuilt("+ x");
expect(built[0].classes).toContain("mord");
expect(built[0].classes).not.toContain("mbin");
});
it("should create ords after some other objects", function() {
expect(getBuilt("x + + 2")[2].classes).toContain("mord");
expect(getBuilt("( + 2")[1].classes).toContain("mord");
expect(getBuilt("= + 2")[1].classes).toContain("mord");
expect(getBuilt("\\sin + 2")[1].classes).toContain("mord");
expect(getBuilt(", + 2")[1].classes).toContain("mord");
});
it("should correctly interact with color objects", function() {
expect(getBuilt("\\blue{x}+y")[1].classes).toContain("mbin");
expect(getBuilt("\\blue{x+}+y")[1].classes).toContain("mord");
});
});

View File

@@ -5,7 +5,7 @@
<script src="jasmine/jasmine-html.js"></script>
<script src="jasmine/boot.js"></script>
<link rel="stylesheet" href="jasmine/jasmine.css">
<script src="katex-tests.js"></script>
<script src="katex-spec.js"></script>
</head>
<body>
</body>