module.exports = function() { | |||||
return "hello world"; | |||||
module.exports = { | |||||
addNumbers(A, B) { | |||||
return A + B; | |||||
}, | |||||
subtractNumbers(A, B) { | |||||
return A - B; | |||||
}, | |||||
message() { | |||||
return "hello world"; | |||||
} | |||||
} | } | ||||
var assert = require('chai').assert; | var assert = require('chai').assert; | ||||
var first = require('../first'); | |||||
var first = require('../first.js'); | |||||
describe('First', function () { | |||||
it('first should return hello world', function () { | |||||
assert.equal(first(), 'hello world'); | |||||
describe('first.js', function () { | |||||
it('Adding 2 numbers works', function () { | |||||
assert.equal(first.addNumbers(3, 4), 7); | |||||
}); | }); | ||||
}); | |||||
it('Adding 2 numbers results in number', function () { | |||||
assert.typeOf(first.addNumbers(3, 4), 'number'); | |||||
}); | |||||
it('Subtract 2 numbers works', function () { | |||||
assert.equal(first.subtractNumbers(4, 3), 1); | |||||
}); | |||||
it('should return hello world ', function () { | |||||
assert.equal(first.message(), 'hello world'); | |||||
}); | |||||
}); | |||||
function sum(a, b) { | |||||
function add(a, b) { | |||||
return a + b; | return a + b; | ||||
} | |||||
} | |||||
function sum() { | |||||
// Convert arguments object to array | |||||
var args = Array.prototype.slice.call(arguments); | |||||
// Throw error if arguments contain non-finite number values | |||||
if (!args.every(Number.isFinite)) { | |||||
throw new TypeError('sum() expects only numbers.') | |||||
} | |||||
// Return the sum of the arguments | |||||
return args.reduce(function(a, b) { | |||||
return a + b | |||||
}, 0); | |||||
} |
import { message } from "../message.js"; | |||||
const assert = chai.assert; | |||||
describe("#esm", function () { | |||||
it("nice message", function () { | |||||
assert.equal('hello, duke', message()); | |||||
}) | |||||
}) | |||||
describe('sum', function () { | |||||
it('should return sum of arguments', function () { | |||||
chai.expect(add(1, 2)).to.equal(3); | |||||
}); | |||||
}); | |||||
describe('sum', function () { | describe('sum', function () { | ||||
it('should return sum of arguments', function () { | it('should return sum of arguments', function () { | ||||
}); | }); | ||||
}); | }); | ||||
mocha.run(); | |||||
<script class="mocha-init"> | <script class="mocha-init"> | ||||
mocha.setup('bdd'); | mocha.setup('bdd'); | ||||
</script> | </script> | ||||
<script src="test.js" type="module"></script> | |||||
<!-- Import the sum function --> | <!-- Import the sum function --> | ||||
<script src="../add.js"></script> | <script src="../add.js"></script> | ||||
<!-- Import the tests for the sum function --> | <!-- Import the tests for the sum function --> | ||||
<script src="addTest.js"></script> | |||||
<script src="test.js" type="module"></script> | |||||
<script> | <script> | ||||
// Run the tests with Mocha | // Run the tests with Mocha | ||||
mocha.run(); | |||||
//mocha.run(); | |||||
</script> | </script> | ||||
</body> | </body> |
assert.equal('hello, duke', message()); | assert.equal('hello, duke', message()); | ||||
}) | }) | ||||
}) | }) | ||||
describe('add', function () { | |||||
it('should return sum of arguments', function () { | |||||
chai.expect(add(1, 2)).to.equal(3); | |||||
}); | |||||
}); | |||||
describe('sum', function () { | |||||
it('should return sum of arguments', function () { | |||||
chai.expect(sum(1, 2)).to.equal(3); | |||||
}); | |||||
}); | |||||
mocha.run(); |
</h2> | </h2> | ||||
<p class="font-weight-bold" id="data"></p> | |||||
<dl> | |||||
<p id="data"></p> | |||||
</dl> | |||||
<form> | <form> | ||||
<div class="form-group"> | <div class="form-group"> | ||||
<label for="NotizInputKey">Notiz nach Thema suchen</label> | <label for="NotizInputKey">Notiz nach Thema suchen</label> | ||||
<input type="NotizInputKey" class="form-control" id="inputKey" placeholder="Thema"> | <input type="NotizInputKey" class="form-control" id="inputKey" placeholder="Thema"> | ||||
<button type="submit" class="btn btn-light" id="search">Notiz nach Thema suchen</button> | <button type="submit" class="btn btn-light" id="search">Notiz nach Thema suchen</button> | ||||
<p class="font-weight-bold" >Gesuchte Notiz:</p> | |||||
<p class="font-weight-normal" >Gesuchte Notiz:</p> | |||||
<p class="font-weight-bold" id="givenKey"></p> | <p class="font-weight-bold" id="givenKey"></p> | ||||
<p class="font-weight-bold" id="notice"></p> | |||||
<p class="font-weight-normal" id="notice"></p> | |||||
<script src="../scripts/notizenAusgabe.js"></script> | <script src="../scripts/notizenAusgabe.js"></script> |
const btnSpeichern = document.getElementById('Speichern'); | |||||
const btnLoeschenKey = document.getElementById('delete_key'); | |||||
const btnAllesLoeschen = document.getElementById('delete_all'); | |||||
const btnEinlesen = document.getElementById('Speichern'); | |||||
function setLocalStorage(key, data) { | |||||
window.localStorage.setItem(key, data); | |||||
} | |||||
function speichern() { | function speichern() { | ||||
var key = document.getElementById('key').value; | var key = document.getElementById('key').value; | ||||
var data = document.getElementById('data').value; | var data = document.getElementById('data').value; | ||||
window.localStorage.setItem(key, data); | |||||
setLocalStorage(key, data); | |||||
} | } | ||||
btnSpeichern.addEventListener('click', e => { | |||||
btnEinlesen.addEventListener('click', e => { | |||||
speichern()}); | speichern()}); | ||||
auslesen(); | auslesen(); | ||||
function getLocalStorageKey(index) { | |||||
return window.localStorage.key(index); | |||||
} | |||||
function getLocalStorageItem(key) { | |||||
return window.localStorage.getItem(key); | |||||
} | |||||
function deleteLocalStorageItem(key) { | |||||
return window.localStorage.removeItem(key); | |||||
} | |||||
function getLocalStorageLength() { | |||||
return window.localStorage.length; | |||||
} | |||||
function auslesen() { | function auslesen() { | ||||
var count = window.localStorage.length; | |||||
var count = getLocalStorageLength(); | |||||
var displayData = document.getElementById('data'); | var displayData = document.getElementById('data'); | ||||
displayData.innerHTML = ""; | displayData.innerHTML = ""; | ||||
if (typeof(Storage) !== "undefined") { | if (typeof(Storage) !== "undefined") { | ||||
for (let i=0; i<count; i++) { | for (let i=0; i<count; i++) { | ||||
var keyname = window.localStorage.key(i); | |||||
var data = window.localStorage.getItem(keyname); | |||||
displayData.innerHTML += keyname+": "+data+"<br>"; | |||||
var keyname = getLocalStorageKey(i); | |||||
var data = getLocalStorageItem(keyname); | |||||
displayData.innerHTML += "<dt>" + keyname+"</dt>" + "<dd>" + data + "</dd>"; | |||||
} | } | ||||
} else { | } else { | ||||
displayData.innerHTML = "Entschuldigung, Ihr Browser unterstützt nicht Web Storage..."; | displayData.innerHTML = "Entschuldigung, Ihr Browser unterstützt nicht Web Storage..."; | ||||
} | } | ||||
} | } | ||||
function finden() { | function finden() { | ||||
var notice = document.getElementById('notice'); | var notice = document.getElementById('notice'); | ||||
givenKey.innerHTML = ""; | givenKey.innerHTML = ""; | ||||
notice.innerHTML = ""; | notice.innerHTML = ""; | ||||
var data = window.localStorage.getItem(keyname); | |||||
givenKey.innerHTML = keyname +":"; | |||||
var data = getLocalStorageItem(keyname); | |||||
givenKey.innerHTML = keyname; | |||||
notice.innerHTML = data; | notice.innerHTML = data; | ||||
} | } | ||||
function loeschen() { | function loeschen() { | ||||
var key = document.getElementById('key').value; | var key = document.getElementById('key').value; | ||||
window.localStorage.removeItem(key); | |||||
deleteLocalStorageItem(key); | |||||
} | } | ||||
function allesLoeschen() { | function allesLoeschen() { |
export default function setStorage2(key, data) { | |||||
window.localStorage.setItem(key, data); | |||||
} |
<!DOCTYPE html> | |||||
<html lang="en"> | |||||
<head> | |||||
<meta charset="utf-8" /> | |||||
<title>Mocha Tests</title> | |||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |||||
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" /> | |||||
</head> | |||||
<body> | |||||
<div id="mocha"></div> | |||||
<script src="https://unpkg.com/chai/chai.js"></script> | |||||
<script src="https://unpkg.com/mocha/mocha.js"></script> | |||||
<script class="mocha-init"> | |||||
mocha.setup('bdd'); | |||||
</script> | |||||
<!-- Import the sum function --> | |||||
<script src="../scripts/notizen.js"></script> | |||||
<script src="../scripts/notizenAusgabe.js"></script> | |||||
<!-- Import the tests for the sum function --> | |||||
<script src="test.js" type="module"></script> | |||||
<script> | |||||
// Run the tests with Mocha | |||||
//mocha.run(); | |||||
</script> | |||||
</body> | |||||
</html> |
import setStorage2 from "../scripts/setStorage2.js"; | |||||
const assert = chai.assert; | |||||
describe('setStorage2 #es6', function () { | |||||
it('should store key/value arguments. Function is a module', function () { | |||||
setStorage2("c", "d"); | |||||
assert.equal("d", window.localStorage.getItem("c")); | |||||
window.localStorage.removeItem("c"); | |||||
}); | |||||
}); | |||||
describe('setLocalStorage', function () { | |||||
it('should store key/value arguments', function () { | |||||
setLocalStorage("a", "b"); | |||||
assert.equal("b", window.localStorage.getItem("a")); | |||||
//chai.expect(window.localStorage.getItem("a")).to.equal("b"); | |||||
window.localStorage.removeItem("a"); | |||||
}); | |||||
it('should has stored key argument', function () { | |||||
setLocalStorage("testkey", "testvalue"); | |||||
assert.hasAnyKeys(window.localStorage, 'testkey'); | |||||
window.localStorage.removeItem("testkey"); | |||||
}); | |||||
}); | |||||
describe('getLocalStorageKey', function () { | |||||
it('should return first key', function () { | |||||
assert.equal(window.localStorage.key(0), getLocalStorageKey(0)); | |||||
}); | |||||
it('should return first key as string value', function () { | |||||
assert.typeOf(window.localStorage.key(0), 'string'); | |||||
}); | |||||
}); | |||||
describe('getLocalStorageItem', function () { | |||||
it('should return item', function () { | |||||
window.localStorage.setItem("e", "f"); | |||||
assert.equal("f", getLocalStorageItem("e")); | |||||
window.localStorage.removeItem("e"); | |||||
}); | |||||
it('should return item as string value', function () { | |||||
window.localStorage.setItem("g", "h"); | |||||
assert.typeOf(getLocalStorageItem("g"), 'string'); | |||||
window.localStorage.removeItem("g"); | |||||
}); | |||||
it('should return item as string value', function () { | |||||
window.localStorage.setItem("myKey2", "myValue2"); | |||||
assert.isString(getLocalStorageItem("myKey2"), 'Item is string'); | |||||
window.localStorage.removeItem("myKey2"); | |||||
}); | |||||
}); | |||||
describe('LocalStorage', function () { | |||||
it('should extensible', function () { | |||||
assert.isExtensible(window.localStorage); | |||||
}); | |||||
it('should not empty', function () { | |||||
assert.isNotEmpty(window.localStorage); | |||||
}); | |||||
it('should empty', function () { | |||||
assert.isEmpty(window.localStorage); | |||||
}); | |||||
it('Local Storage should be an object', function () { | |||||
assert.isObject(window.localStorage, 'Yes local storage is an object!'); | |||||
}); | |||||
it('Local Storage should be ok', function () { | |||||
assert.isOk(window.localStorage, 'Yes local storage is ok!'); | |||||
}); | |||||
}); | |||||
describe('deleteLocalStorageItem', function () { | |||||
it('should deleted key=i/value=l', function () { | |||||
window.localStorage.setItem("i", "j"); | |||||
deleteLocalStorageItem("i"); | |||||
assert.doesNotHaveAnyKeys(window.localStorage, 'i'); | |||||
}); | |||||
it('Local Storage list should be smaller if key/value pair is deleted', function () { | |||||
window.localStorage.setItem("k", "l"); | |||||
var preCount = window.localStorage.length; | |||||
deleteLocalStorageItem("k"); | |||||
var postCount = window.localStorage.length; | |||||
assert.operator(postCount, '<', preCount, 'is smaller, ok'); | |||||
}); | |||||
}); | |||||
describe('getLocalStorageLength', function () { | |||||
it('should return local storage length', function () { | |||||
assert.lengthOf(window.localStorage, getLocalStorageLength()); | |||||
}); | |||||
}); | |||||
mocha.checkLeaks(); | |||||
mocha.run(); |