generated from amiraabouhadid/webpack-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit tests for add and remove task functions
- Loading branch information
1 parent
9b4d659
commit 60c9add
Showing
9 changed files
with
973 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
dist | ||
coverage |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const foo = "foo"; | ||
export const bar = () => "bar"; | ||
export default () => "baz"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { getTasks } from "./src/modules/getTasks"; | ||
import Home from "./src/modules/Home"; | ||
class LocalStorageMock { | ||
constructor() { | ||
this.store = {}; | ||
} | ||
|
||
clear() { | ||
this.store = {}; | ||
} | ||
|
||
getItem(key) { | ||
return this.store[key] || null; | ||
} | ||
|
||
setItem(key, value) { | ||
this.store[key] = String(value); | ||
} | ||
|
||
removeItem(key) { | ||
delete this.store[key]; | ||
} | ||
} | ||
|
||
global.localStorage = new LocalStorageMock(); | ||
let window; | ||
beforeEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
||
describe("add and delete task", () => { | ||
test("adds task", () => { | ||
console.log("starting first test..."); | ||
let tasks; | ||
const e = { target: { value: "buy food" } }; | ||
|
||
Home.addTask(e); | ||
tasks = getTasks(); | ||
expect(tasks).toHaveLength(1); | ||
}); | ||
test("deletes task", () => { | ||
console.log("starting second test..."); | ||
let initialTasks = [ | ||
{ complete: "true", description: "buy batteries", index: "0" }, | ||
{ complete: "false", description: "buy batteries", index: "1" }, | ||
]; | ||
localStorage.setItem("tasks", JSON.stringify(initialTasks)); | ||
|
||
Home.deleteTask(initialTasks[0]); | ||
let tasks = JSON.parse(localStorage.getItem("tasks")); | ||
expect(tasks).toHaveLength(1); | ||
}); | ||
}); |
Oops, something went wrong.