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:
Kevin Barabash
2017-07-11 14:16:26 -04:00
committed by Erik Demaine
parent 4480f2c987
commit 361c500a7f
12 changed files with 228 additions and 275 deletions

View File

@@ -1,5 +1,4 @@
/* global beforeEach: false */
/* global jasmine: false */
/* global expect: false */
/* global it: false */
/* global describe: false */
@@ -7,60 +6,56 @@
const splitAtDelimiters = require("./splitAtDelimiters");
beforeEach(function() {
jasmine.addMatchers({
toSplitInto: function() {
return {
compare: function(actual, left, right, result) {
const message = {
pass: true,
message: "'" + actual + "' split correctly",
};
const startData = [{type: "text", data: actual}];
const split =
splitAtDelimiters(startData, left, right, false);
if (split.length !== result.length) {
message.pass = false;
message.message = "Different number of splits: " +
split.length + " vs. " + result.length + " (" +
JSON.stringify(split) + " vs. " +
JSON.stringify(result) + ")";
return message;
}
for (let i = 0; i < split.length; i++) {
const real = split[i];
const correct = result[i];
let good = true;
let diff;
if (real.type !== correct.type) {
good = false;
diff = "type";
} else if (real.data !== correct.data) {
good = false;
diff = "data";
} else if (real.display !== correct.display) {
good = false;
diff = "display";
}
if (!good) {
message.pass = false;
message.message = "Difference at split " +
(i + 1) + ": " + JSON.stringify(real) +
" vs. " + JSON.stringify(correct) +
" (" + diff + " differs)";
break;
}
}
return message;
},
expect.extend({
toSplitInto: function(actual, left, right, result) {
const message = {
pass: true,
message: "'" + actual + "' split correctly",
};
const startData = [{type: "text", data: actual}];
const split =
splitAtDelimiters(startData, left, right, false);
if (split.length !== result.length) {
message.pass = false;
message.message = "Different number of splits: " +
split.length + " vs. " + result.length + " (" +
JSON.stringify(split) + " vs. " +
JSON.stringify(result) + ")";
return message;
}
for (let i = 0; i < split.length; i++) {
const real = split[i];
const correct = result[i];
let good = true;
let diff;
if (real.type !== correct.type) {
good = false;
diff = "type";
} else if (real.data !== correct.data) {
good = false;
diff = "data";
} else if (real.display !== correct.display) {
good = false;
diff = "display";
}
if (!good) {
message.pass = false;
message.message = "Difference at split " +
(i + 1) + ": " + JSON.stringify(real) +
" vs. " + JSON.stringify(correct) +
" (" + diff + " differs)";
break;
}
}
return message;
},
});
});