Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

class_spec.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. const path = require("path");
  2. const { JSDOM } = require("jsdom");
  3. describe("File js/class", function () {
  4. describe("Test function cloneObject", function () {
  5. let clone;
  6. let dom;
  7. beforeAll(function (done) {
  8. dom = new JSDOM(
  9. `<script>var Log = {log: function() {}};</script>\
  10. <script src="file://${path.join(__dirname, "..", "..", "..", "js", "class.js")}">`,
  11. { runScripts: "dangerously", resources: "usable" }
  12. );
  13. dom.window.onload = function () {
  14. const { cloneObject } = dom.window;
  15. clone = cloneObject;
  16. done();
  17. };
  18. });
  19. it("should clone object", function () {
  20. const expected = { name: "Rodrigo", web: "https://rodrigoramirez.com", project: "MagicMirror" };
  21. const obj = clone(expected);
  22. expect(obj).toEqual(expected);
  23. expect(expected === obj).toBe(false);
  24. });
  25. it("should clone array", function () {
  26. const expected = [1, null, undefined, "TEST"];
  27. const obj = clone(expected);
  28. expect(obj).toEqual(expected);
  29. expect(expected === obj).toBe(false);
  30. });
  31. it("should clone number", function () {
  32. let expected = 1;
  33. let obj = clone(expected);
  34. expect(obj).toBe(expected);
  35. expected = 1.23;
  36. obj = clone(expected);
  37. expect(obj).toBe(expected);
  38. });
  39. it("should clone string", function () {
  40. const expected = "Perfect stranger";
  41. const obj = clone(expected);
  42. expect(obj).toBe(expected);
  43. });
  44. it("should clone undefined", function () {
  45. const expected = undefined;
  46. const obj = clone(expected);
  47. expect(obj).toBe(expected);
  48. });
  49. it("should clone null", function () {
  50. const expected = null;
  51. const obj = clone(expected);
  52. expect(obj).toBe(expected);
  53. });
  54. it("should clone nested object", function () {
  55. const expected = {
  56. name: "fewieden",
  57. link: "https://github.com/fewieden",
  58. versions: ["2.0", "2.1", "2.2"],
  59. answerForAllQuestions: 42,
  60. properties: {
  61. items: [{ foo: "bar" }, { lorem: "ipsum" }],
  62. invalid: undefined,
  63. nothing: null
  64. }
  65. };
  66. const obj = clone(expected);
  67. expect(obj).toEqual(expected);
  68. expect(expected === obj).toBe(false);
  69. expect(expected.versions === obj.versions).toBe(false);
  70. expect(expected.properties === obj.properties).toBe(false);
  71. expect(expected.properties.items === obj.properties.items).toBe(false);
  72. expect(expected.properties.items[0] === obj.properties.items[0]).toBe(false);
  73. expect(expected.properties.items[1] === obj.properties.items[1]).toBe(false);
  74. });
  75. describe("Test lockstring code", function () {
  76. let log;
  77. beforeAll(function () {
  78. log = dom.window.Log.log;
  79. dom.window.Log.log = function cmp(str) {
  80. expect(str).toBe("lockStrings");
  81. };
  82. });
  83. afterAll(function () {
  84. dom.window.Log.log = log;
  85. });
  86. it("should clone object and log lockStrings", function () {
  87. const expected = { name: "Module", lockStrings: "stringLock" };
  88. const obj = clone(expected);
  89. expect(obj).toEqual(expected);
  90. expect(expected === obj).toBe(false);
  91. });
  92. });
  93. });
  94. });