mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
compare version unit test
This commit is contained in:
parent
20244c4fb5
commit
d81d7d4f68
@ -476,11 +476,3 @@ Module.register = function (name, moduleDefinition) {
|
||||
Log.log("Module registered: " + name);
|
||||
Module.definitions[name] = moduleDefinition;
|
||||
};
|
||||
|
||||
if (typeof exports != "undefined") { // For testing purpose only
|
||||
// A good a idea move the function cmpversions a helper file.
|
||||
// It's used into other side.
|
||||
exports._test = {
|
||||
cmpVersions: cmpVersions
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,32 @@
|
||||
var chai = require("chai");
|
||||
var expect = chai.expect;
|
||||
var classMM = require("../../../js/class.js"); // require for load module.js
|
||||
var moduleMM = require("../../../js/module.js")
|
||||
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() {
|
||||
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() {
|
||||
expect(moduleMM._test.cmpVersions("2.1", "2.2")).to.equal(-1);
|
||||
expect(cmp("2.1", "2.2")).to.equal(-1);
|
||||
});
|
||||
|
||||
it("should be return 0 when comparing 2.2 to 2.2", function() {
|
||||
expect(moduleMM._test.cmpVersions("2.2", "2.2")).to.equal(0);
|
||||
expect(cmp("2.2", "2.2")).to.equal(0);
|
||||
});
|
||||
|
||||
it("should be return 1 when comparing 1.1 to 1.0", function() {
|
||||
expect(moduleMM._test.cmpVersions("1.1", "1.0")).to.equal(1);
|
||||
expect(cmp("1.1", "1.0")).to.equal(1);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user