mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-07 04:08:43 +00:00
Switch from jasmine to jest (#747)
Summary: The reasons for switching to jest: - easy snapshot testing so that we can easily verify the structure of the parse tree and MathML tree - easy compilation of ES6 features for tests as we continue to expand our use of ES6 Test Plan: - npm test
This commit is contained in:
committed by
Erik Demaine
parent
4480f2c987
commit
361c500a7f
@@ -1,5 +1,4 @@
|
||||
/* global beforeEach: false */
|
||||
/* global jasmine: false */
|
||||
/* global expect: false */
|
||||
/* global it: false */
|
||||
/* global describe: false */
|
||||
@@ -10,50 +9,47 @@ import Settings from "../src/Settings";
|
||||
const defaultSettings = new Settings({});
|
||||
|
||||
beforeEach(function() {
|
||||
jasmine.addMatchers({
|
||||
toFailWithParseError: function(util, customEqualityTesters) {
|
||||
const prefix = "KaTeX parse error: ";
|
||||
return {
|
||||
compare: function(actual, expected) {
|
||||
try {
|
||||
parseTree(actual, defaultSettings);
|
||||
return {
|
||||
pass: false,
|
||||
message: "'" + actual + "' parsed without error",
|
||||
};
|
||||
} catch (e) {
|
||||
if (expected === undefined) {
|
||||
return {
|
||||
pass: true,
|
||||
message: "'" + actual + "' parsed with error",
|
||||
};
|
||||
}
|
||||
const msg = e.message;
|
||||
const exp = prefix + expected;
|
||||
if (msg === exp) {
|
||||
return {
|
||||
pass: true,
|
||||
message: "'" + actual + "'" +
|
||||
" parsed with error '" + expected + "'",
|
||||
};
|
||||
} else if (msg.slice(0, 19) === prefix) {
|
||||
return {
|
||||
pass: false,
|
||||
message: "'" + actual + "'" +
|
||||
" parsed with error '" + msg.slice(19) +
|
||||
"' but expected '" + expected + "'",
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
pass: false,
|
||||
message: "'" + actual + "'" +
|
||||
" caused error '" + msg +
|
||||
"' but expected '" + exp + "'",
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
const prefix = "KaTeX parse error: ";
|
||||
|
||||
expect.extend({
|
||||
toFailWithParseError: function(actual, expected) {
|
||||
try {
|
||||
parseTree(actual, defaultSettings);
|
||||
return {
|
||||
pass: false,
|
||||
message: "'" + actual + "' parsed without error",
|
||||
};
|
||||
} catch (e) {
|
||||
if (expected === undefined) {
|
||||
return {
|
||||
pass: true,
|
||||
message: "'" + actual + "' parsed with error",
|
||||
};
|
||||
}
|
||||
const msg = e.message;
|
||||
const exp = prefix + expected;
|
||||
if (msg === exp) {
|
||||
return {
|
||||
pass: true,
|
||||
message: "'" + actual + "'" +
|
||||
" parsed with error '" + expected + "'",
|
||||
};
|
||||
} else if (msg.slice(0, 19) === prefix) {
|
||||
return {
|
||||
pass: false,
|
||||
message: "'" + actual + "'" +
|
||||
" parsed with error '" + msg.slice(19) +
|
||||
"' but expected '" + expected + "'",
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
pass: false,
|
||||
message: "'" + actual + "'" +
|
||||
" caused error '" + msg +
|
||||
"' but expected '" + exp + "'",
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user