MagicMirror/tests/unit/functions/cmp_versions_spec.js

32 lines
826 B
JavaScript
Raw Normal View History

2018-02-15 23:53:57 +01:00
const path = require("path");
const { JSDOM } = require("jsdom");
describe("Test function cmpVersions in js/module.js", () => {
2018-02-15 23:53:57 +01:00
let cmp;
beforeAll((done) => {
const dom = new JSDOM(
`<script>var Class = {extend: () => { return {}; }};</script>\
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "module.js")}">`,
{ runScripts: "dangerously", resources: "usable" }
);
dom.window.onload = () => {
const { cmpVersions } = dom.window;
2018-02-15 23:53:57 +01:00
cmp = cmpVersions;
done();
};
});
it("should return -1 when comparing 2.1 to 2.2", () => {
2021-06-08 00:47:15 +02:00
expect(cmp("2.1", "2.2")).toBe(-1);
});
it("should be return 0 when comparing 2.2 to 2.2", () => {
2021-06-08 00:47:15 +02:00
expect(cmp("2.2", "2.2")).toBe(0);
});
it("should be return 1 when comparing 1.1 to 1.0", () => {
2021-06-08 00:47:15 +02:00
expect(cmp("1.1", "1.0")).toBe(1);
});
});