clone object unit test

This commit is contained in:
fewieden
2018-02-16 00:01:02 +01:00
parent d81d7d4f68
commit 96b2f2b3a4
2 changed files with 30 additions and 22 deletions

View File

@@ -92,7 +92,4 @@ function cloneObject(obj) {
/*************** DO NOT EDIT THE LINE BELOW ***************/ /*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") { if (typeof module !== "undefined") {
module.exports = Class; module.exports = Class;
module.exports._test = {
cloneObject: cloneObject
}
} }

View File

@@ -1,36 +1,47 @@
var chai = require("chai"); const chai = require("chai");
var expect = chai.expect; const expect = chai.expect;
var jsClass = require("../../../js/class.js"); const path = require("path");
const {JSDOM} = require("jsdom");
describe("File js/class", function() { describe("File js/class", function() {
describe("Test function cloneObject", function() { describe("Test function cloneObject", function() {
var cloneObject = jsClass._test.cloneObject; let clone;
before(function(done) {
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "class.js")}">`, { runScripts: "dangerously",
resources: "usable" });
dom.window.onload = function() {
const {cloneObject} = dom.window;
clone = cloneObject;
done();
};
});
it("should be return equals object", function() { it("should be return equals object", function() {
var expected = {name: "Rodrigo", web: "https://rodrigoramirez.com", project: "MagicMirror"}; const expected = {name: "Rodrigo", web: "https://rodrigoramirez.com", project: "MagicMirror"};
var obj = {}; let obj = {};
obj = cloneObject(expected); obj = clone(expected);
expect(expected).to.deep.equal(obj); expect(expected).to.deep.equal(obj);
}); });
it("should be return equals int", function() { it("should be return equals int", function() {
var expected = 1; const expected = 1;
var obj = {}; let obj = {};
obj = cloneObject(expected); obj = clone(expected);
expect(expected).to.equal(obj); expect(expected).to.equal(obj);
}); });
it("should be return equals string", function() { it("should be return equals string", function() {
var expected = "Perfect stranger"; const expected = "Perfect stranger";
var obj = {}; let obj = {};
obj = cloneObject(expected); obj = clone(expected);
expect(expected).to.equal(obj); expect(expected).to.equal(obj);
}); });
it("should be return equals undefined", function() { it("should be return equals undefined", function() {
var expected = undefined; const expected = undefined;
var obj = {}; let obj = {};
obj = cloneObject(expected); obj = clone(expected);
expect(undefined).to.equal(obj); expect(undefined).to.equal(obj);
}); });
@@ -38,9 +49,9 @@ describe("File js/class", function() {
/* /*
context("Test lockstring code", function() { context("Test lockstring code", function() {
it("should be return equals object", function() { it("should be return equals object", function() {
var expected = {name: "Module", lockStrings: "stringLock"}; const expected = {name: "Module", lockStrings: "stringLock"};
var obj = {}; let obj = {};
obj = cloneObject(expected); obj = clone(expected);
expect(expected).to.deep.equal(obj); expect(expected).to.deep.equal(obj);
}); });
}); });