Skip to content

Commit

Permalink
testing DOM
Browse files Browse the repository at this point in the history
  • Loading branch information
TeodorDimitrov89 committed Nov 11, 2022
1 parent c2ef75f commit f9c62c8
Show file tree
Hide file tree
Showing 15 changed files with 2,776 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,5 @@ dist
/02.good-tests/node_modules
/03.integration-tests/node_modules
/04.advanced-testing/node_modules
/05.mocking-spies/node_modules
/05.mocking-spies/node_modules
/06.testing-DOM/node_modules
17 changes: 17 additions & 0 deletions 06.testing-DOM/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { extractPostData, savePost } from './posts/posts.js';

const formElement = document.querySelector('form');

export async function submitFormHandler(event) {
event.preventDefault();

const formData = new FormData(formElement);
try {
const postData = extractPostData(formData);
await savePost(postData);
} catch (error) {
showError(error.message);
}
}

formElement.addEventListener('submit', submitFormHandler);
24 changes: 24 additions & 0 deletions 06.testing-DOM/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>More on Mocks</title>
<script src="app.js" type="module" defer></script>
</head>
<body>
<form>
<div>
<label for="title">Title</label>
<input type="text" id="title" name="title" />
</div>
<div>
<label for="content">Content</label>
<textarea id="content" name="content" rows="5"></textarea>
</div>
<button>Save Post</button>
<div id="errors"></div>
</form>
</body>
</html>
Loading

0 comments on commit f9c62c8

Please sign in to comment.