You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-3/todo-list/01-using_esm_with_nodejs_and_jest.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,8 @@
4
4
5
5
Node.js supports both CommonJS and ESM, with CommonJS being the default module system.
6
6
7
-
To use ESM, we can add `"type": "module"` to `package.json`, or we can name the JS script files with `.mjs` file extension.
7
+
To use ESM, we can add `"type": "module"` to `package.json`, or we can name the JavaScript files
8
+
with `.mjs` file extension.
8
9
9
10
**Important**:
10
11
- Avoid mixing CommonJS and ESM in the same project unless you know what you're doing.
@@ -37,11 +38,13 @@ One way to execute Jest test script that uses ESM is to
37
38
npm test -- <test_script_filename>
38
39
```
39
40
40
-
**Note**: The `--` is optional if you do not have arguments to be forwarded to the underlying jest command.
41
+
**Note**: The `--` is optional if you do not have arguments to be forwarded to the underlying
42
+
`jest` command.
41
43
42
44
43
45
## `jsdom`
44
46
45
-
[**`jsdom`**](https://github.com/jsdom/jsdom), a pure-JavaScript implementation of DOM for use with Node.js, **does not yet support**`<script type="module">` tags in HTML.
47
+
[**`jsdom`**](https://github.com/jsdom/jsdom), a pure-JavaScript implementation of DOM for
48
+
use with Node.js, **does not yet support**`<script type="module">` tags in HTML.
46
49
47
50
Testing an ESM-based application with `jsdom` requires additional configuration and third-party tooling.
Copy file name to clipboardExpand all lines: Sprint-3/todo-list/02-guide_to_modularize_code.md
+14-3Lines changed: 14 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
# Why modularize code?
2
2
3
-
Modularizing code means breaking a program into smaller, self-contained pieces (modules), each responsible for a specific functionality. This approach offers several key advantages:
3
+
Modularizing code means breaking a program into smaller, self-contained pieces (modules),
4
+
each responsible for a specific functionality. This approach offers several key advantages:
4
5
5
6
- Reusability – You can use the same code in different parts of a project or in other projects.
6
7
- Maintainability – It's easier to fix bugs or update features when code is organized into smaller parts.
@@ -12,9 +13,19 @@ Modularizing code means breaking a program into smaller, self-contained pieces (
12
13
13
14
## How to break a program into smaller modules?
14
15
15
-
This is a relatively big topic and you will learn more about how to modularize a web app in the SDC course.
16
+
This is a relatively big topic and you will learn more about how to modularize a web app in the
17
+
SDC course.
16
18
17
-
For starters, we recommend focusing on breaking a web app into the **non-UI part** and the **UI part**.
19
+
For starters, we recommend focusing on breaking a web app into the **non-UI part** and
20
+
the **UI part**. Some of the advantages of doing so include:
21
+
22
+
1. Easier Testing
23
+
- Non-UI code can be tested independently with unit tests.
24
+
- You don't need browser environments or DOM simulations (e.g., `jsdom`) for testing logic.
25
+
26
+
2. Easier Collaboration
27
+
- UI developers and business-logic developers can work more independently.
28
+
- Clearer separation of concerns makes the codebase easier to maintain over time.
Copy file name to clipboardExpand all lines: Sprint-3/todo-list/README.md
+28-14Lines changed: 28 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,25 +24,39 @@ To view the website, open `index.html` with Live Server in VS Code.
24
24
25
25
## Instructions
26
26
27
-
In this exercise, your objective is to implement additional features.
27
+
In this exercise, your objective is to extend the ToDo app by implementing new features.
28
+
Start with the main feature and then try the stretch goals if you have extra time.
28
29
29
-
#### Feature 1: Mass delete of completed ToDos
30
+
###Main Feature: Mass delete of completed ToDos
30
31
31
-
Add a "Delete completed tasks" button that, when clicked, will delete all the completed ToDos. You should
32
-
- In `todos.mjs`, implement a function to delete all completed tasks in the given ToDo List
33
-
- In `todos.test.mjs`, implement a test to check your function.
34
-
- In `script.js`, call the function to delete all completed tasks whenever the user clicks a "Delete All" button.
32
+
Add a button that deletes all completed tasks at once.
35
33
36
-
#### Stretch 1: Set deadlines for ToDos
34
+
Steps:
35
+
1. In `index.html`, add a "Delete completed tasks" button.
37
36
38
-
We want users to be able to set, and see, deadlines for their ToDos.
37
+
2. In `todos.mjs`, implement a function `deleteCompleted(todoList)` that removes all completed
38
+
ToDos from the given list.
39
39
40
-
When creating a ToDo we want the user to be able to use a datepicker input to specify a deadline for the Todo.
41
-
If no date is selected, the ToDo is considered having no deadline.
40
+
3. In `todos.test.mjs`, write a Jest test that verifies `deleteCompleted()` works correctly.
41
+
42
+
4. In `script.js`, call `deleteCompleted()` whenever the new button is clicked.
43
+
- ⚠️ You should not need to modify the `render()` function.
44
+
45
+
### Stretch 1: Add deadlines for ToDos
46
+
47
+
Allow users to set and view deadlines for their tasks.
48
+
- When creating a ToDo, let the user select a deadline using an HTML **datepicker** input.
49
+
- If no date is selected, the ToDo has **no deadline**.
50
+
- When rendering a ToDo in the list, display the deadline only if it exists.
51
+
52
+
### Stretch 2: Extra Challenge – Show time remaining
53
+
54
+
Instead of showing the deadline as a date, display how many days are left until the
55
+
deadline (relative to today).
56
+
- Decide how overdue ToDos should be handled and then implement your chosen solution.
57
+
58
+
👉 Hint: You can use the [JavaScript Date API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
59
+
to calculate the difference.
42
60
43
-
When displaying a ToDo in the list, display the deadline only if the ToDo has one.
44
61
45
-
#### Stretch 2: EXTRA CHALLENGE
46
62
47
-
Instead of displaying the date on the ToDo, implement a countdown of days left until the deadline. You can use the Javascript Date reference to accomplish this:
0 commit comments