MagicMirror/tests/unit/functions/cmp_versions_spec.js

33 lines
911 B
JavaScript
Raw Normal View History

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