Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
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.

test.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import setStorage2 from "../scripts/setStorage2.js";
  2. const assert = chai.assert;
  3. describe('setStorage2 #es6', function () {
  4. it('should store key/value arguments. Function is a module', function () {
  5. setStorage2("c", "d");
  6. assert.equal("d", window.localStorage.getItem("c"));
  7. window.localStorage.removeItem("c");
  8. });
  9. });
  10. describe('setLocalStorage', function () {
  11. it('should store key/value arguments', function () {
  12. setLocalStorage("a", "b");
  13. assert.equal("b", window.localStorage.getItem("a"));
  14. //chai.expect(window.localStorage.getItem("a")).to.equal("b");
  15. window.localStorage.removeItem("a");
  16. });
  17. it('should has stored key argument', function () {
  18. setLocalStorage("testkey", "testvalue");
  19. assert.hasAnyKeys(window.localStorage, 'testkey');
  20. window.localStorage.removeItem("testkey");
  21. });
  22. });
  23. describe('getLocalStorageKey', function () {
  24. it('should return first key', function () {
  25. assert.equal(window.localStorage.key(0), getLocalStorageKey(0));
  26. });
  27. it('should return first key as string value', function () {
  28. assert.typeOf(window.localStorage.key(0), 'string');
  29. });
  30. });
  31. describe('getLocalStorageItem', function () {
  32. it('should return item', function () {
  33. window.localStorage.setItem("e", "f");
  34. assert.equal("f", getLocalStorageItem("e"));
  35. window.localStorage.removeItem("e");
  36. });
  37. it('should return item as string value', function () {
  38. window.localStorage.setItem("g", "h");
  39. assert.typeOf(getLocalStorageItem("g"), 'string');
  40. window.localStorage.removeItem("g");
  41. });
  42. it('should return item as string value', function () {
  43. window.localStorage.setItem("myKey2", "myValue2");
  44. assert.isString(getLocalStorageItem("myKey2"), 'Item is string');
  45. window.localStorage.removeItem("myKey2");
  46. });
  47. });
  48. describe('LocalStorage', function () {
  49. it('should extensible', function () {
  50. assert.isExtensible(window.localStorage);
  51. });
  52. it('should not empty', function () {
  53. assert.isNotEmpty(window.localStorage);
  54. });
  55. it('should empty', function () {
  56. assert.isEmpty(window.localStorage);
  57. });
  58. it('Local Storage should be an object', function () {
  59. assert.isObject(window.localStorage, 'Yes local storage is an object!');
  60. });
  61. it('Local Storage should be ok', function () {
  62. assert.isOk(window.localStorage, 'Yes local storage is ok!');
  63. });
  64. });
  65. describe('deleteLocalStorageItem', function () {
  66. it('should deleted key=i/value=l', function () {
  67. window.localStorage.setItem("i", "j");
  68. deleteLocalStorageItem("i");
  69. assert.doesNotHaveAnyKeys(window.localStorage, 'i');
  70. });
  71. it('Local Storage list should be smaller if key/value pair is deleted', function () {
  72. window.localStorage.setItem("k", "l");
  73. var preCount = window.localStorage.length;
  74. deleteLocalStorageItem("k");
  75. var postCount = window.localStorage.length;
  76. assert.operator(postCount, '<', preCount, 'is smaller, ok');
  77. });
  78. });
  79. describe('getLocalStorageLength', function () {
  80. it('should return local storage length', function () {
  81. assert.lengthOf(window.localStorage, getLocalStorageLength());
  82. });
  83. });
  84. mocha.checkLeaks();
  85. mocha.run();