Skip to content
Open

finish #1536

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/test.yml-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test

on:
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm start & sleep 5 && npm test
- name: Upload tests report(cypress mochaawesome merged HTML report)
if: ${{ always() }}
uses: actions/upload-artifact@v2
with:
name: report
path: reports
181 changes: 5 additions & 176 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
"postinstall": "npm run update",
"test": "npm run lint && npm run test:only"
},
"dependencies": {},
"devDependencies": {
"@linthtml/linthtml": "^0.9.6",
"@mate-academy/eslint-config": "latest",
"@mate-academy/jest-mochawesome-reporter": "^1.0.0",
"@mate-academy/linthtml-config": "latest",
"@mate-academy/scripts": "^1.8.5",
"@mate-academy/scripts": "^2.1.3",
"@mate-academy/stylelint-config": "latest",
"@parcel/transformer-sass": "^2.12.0",
"cypress": "^13.13.0",
Expand Down
29 changes: 29 additions & 0 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
'use strict';

// write your code here
const logo = document.querySelector('.logo');

const promise1 = new Promise((resolve) => {
logo.addEventListener('click', () => {
resolve('Promise was resolved!');
});
});

const promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error(`Promise was rejected!`));
}, 3000);
});

promise1.then((message) => {
const div = document.createElement('div');

div.classList.add('message');
div.textContent = message;
document.body.appendChild(div);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requirement #4 states handlers should be added for 'both promises'. Currently promise1 only has .then() but no .catch() handler. Add promise1.catch() with the same error div creation logic.


promise2.catch((message) => {
const div = document.createElement('div');

div.classList.add('message', 'error-message');
div.textContent = message;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reject() call passes an Error object, but setting div.textContent = message will display '[object Object]' instead of the error text. Use message.message or message.toString() to get the actual error text.

document.body.appendChild(div);
Comment on lines +12 to +18
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

promise2 needs a .then() success handler in addition to .catch(). Even though promise2 rejects, it still requires a success handler per the 'both promises' requirement.

});
Loading