mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2024-12-27 09:29:10 +00:00
switch to mocha for test latency improvements
Signed-off-by: Arthur Lu <learthurgo@gmail.com>
This commit is contained in:
parent
c7c395c832
commit
0f622d16de
@ -2,9 +2,9 @@
|
||||
"name": "food-journal",
|
||||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"test": "jest"
|
||||
"test": "mocha --recursive **/*.test.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"jest": "24"
|
||||
"mocha": "10"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
const {environment} = require("./testenv.js");
|
||||
var assert = require('assert');
|
||||
var window;
|
||||
|
||||
function saveToLocal (k, v) {
|
||||
window.localStorage.setItem(k, v);
|
||||
@ -17,24 +19,35 @@ function clearLocal () {
|
||||
}
|
||||
|
||||
describe("test localStorage mock", () => {
|
||||
test("test save and fetch", () => {
|
||||
let window = environment();
|
||||
it("test save and fetch", () => {
|
||||
window = environment();
|
||||
|
||||
saveToLocal("testkey1", "testvalue1");
|
||||
saveToLocal("testkey2", "testvalue2");
|
||||
saveToLocal("testkey3", "testvalue3");
|
||||
saveToLocal("testkey4", "testvalue4");
|
||||
|
||||
expect(getFromLocal("testkey1")).toStrictEqual("testvalue1");
|
||||
expect(getFromLocal("testkey2")).toStrictEqual("testvalue2");
|
||||
expect(getFromLocal("testkey3")).toStrictEqual("testvalue3");
|
||||
expect(getFromLocal("testkey4")).toStrictEqual("testvalue4");
|
||||
assert.equal(getFromLocal("testkey1"), "testvalue1");
|
||||
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
||||
assert.equal(getFromLocal("testkey3"), "testvalue3");
|
||||
assert.equal(getFromLocal("testkey4"), "testvalue4");
|
||||
|
||||
saveToLocal("testkey6", "testvalue5");
|
||||
expect(getFromLocal("testkey6")).toStrictEqual("testvalue5");
|
||||
assert.equal(getFromLocal("testkey6"), "testvalue5");
|
||||
});
|
||||
|
||||
test("test delete and fetch", () => {
|
||||
let window = environment();
|
||||
it("test window locality", () => {
|
||||
window = environment();
|
||||
|
||||
assert.equal(getFromLocal("testkey1"), null);
|
||||
assert.equal(getFromLocal("testkey2"), null);
|
||||
assert.equal(getFromLocal("testkey3"), null);
|
||||
assert.equal(getFromLocal("testkey4"), null);
|
||||
});
|
||||
|
||||
it("test delete and fetch", () => {
|
||||
window = environment();
|
||||
|
||||
saveToLocal("testkey1", "testvalue1");
|
||||
saveToLocal("testkey2", "testvalue2");
|
||||
saveToLocal("testkey3", "testvalue3");
|
||||
@ -42,35 +55,36 @@ describe("test localStorage mock", () => {
|
||||
|
||||
removeFromLocal("testkey3");
|
||||
|
||||
expect(getFromLocal("testkey1")).toStrictEqual("testvalue1");
|
||||
expect(getFromLocal("testkey2")).toStrictEqual("testvalue2");
|
||||
expect(getFromLocal("testkey3")).toStrictEqual(null);
|
||||
expect(getFromLocal("testkey4")).toStrictEqual("testvalue4");
|
||||
assert.equal(getFromLocal("testkey1"), "testvalue1");
|
||||
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
||||
assert.equal(getFromLocal("testkey3"), null);
|
||||
assert.equal(getFromLocal("testkey4"), "testvalue4");
|
||||
|
||||
removeFromLocal("testkey1");
|
||||
|
||||
expect(getFromLocal("testkey1")).toStrictEqual(null);
|
||||
expect(getFromLocal("testkey2")).toStrictEqual("testvalue2");
|
||||
expect(getFromLocal("testkey3")).toStrictEqual(null);
|
||||
expect(getFromLocal("testkey4")).toStrictEqual("testvalue4");
|
||||
assert.equal(getFromLocal("testkey1"), null);
|
||||
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
||||
assert.equal(getFromLocal("testkey3"), null);
|
||||
assert.equal(getFromLocal("testkey4"), "testvalue4");
|
||||
|
||||
removeFromLocal("testkey4");
|
||||
|
||||
expect(getFromLocal("testkey1")).toStrictEqual(null);
|
||||
expect(getFromLocal("testkey2")).toStrictEqual("testvalue2");
|
||||
expect(getFromLocal("testkey3")).toStrictEqual(null);
|
||||
expect(getFromLocal("testkey4")).toStrictEqual(null);
|
||||
assert.equal(getFromLocal("testkey1"), null);
|
||||
assert.equal(getFromLocal("testkey2"), "testvalue2");
|
||||
assert.equal(getFromLocal("testkey3"), null);
|
||||
assert.equal(getFromLocal("testkey4"), null);
|
||||
|
||||
removeFromLocal("testkey2");
|
||||
|
||||
expect(getFromLocal("testkey1")).toStrictEqual(null);
|
||||
expect(getFromLocal("testkey2")).toStrictEqual(null);
|
||||
expect(getFromLocal("testkey3")).toStrictEqual(null);
|
||||
expect(getFromLocal("testkey4")).toStrictEqual(null);
|
||||
assert.equal(getFromLocal("testkey1"), null);
|
||||
assert.equal(getFromLocal("testkey2"), null);
|
||||
assert.equal(getFromLocal("testkey3"), null);
|
||||
assert.equal(getFromLocal("testkey4"), null);
|
||||
});
|
||||
|
||||
test("test clear and fetch", () => {
|
||||
let window = environment();
|
||||
it("test clear and fetch", () => {
|
||||
window = environment();
|
||||
|
||||
saveToLocal("testkey1", "testvalue1");
|
||||
saveToLocal("testkey2", "testvalue2");
|
||||
saveToLocal("testkey3", "testvalue3");
|
||||
@ -78,9 +92,9 @@ describe("test localStorage mock", () => {
|
||||
|
||||
clearLocal();
|
||||
|
||||
expect(getFromLocal("testkey1")).toStrictEqual(null);
|
||||
expect(getFromLocal("testkey2")).toStrictEqual(null);
|
||||
expect(getFromLocal("testkey3")).toStrictEqual(null);
|
||||
expect(getFromLocal("testkey4")).toStrictEqual(null);
|
||||
assert.equal(getFromLocal("testkey1"), null);
|
||||
assert.equal(getFromLocal("testkey2"), null);
|
||||
assert.equal(getFromLocal("testkey3"), null);
|
||||
assert.equal(getFromLocal("testkey4"), null);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user