88 lines
3.0 KiB
Markdown
88 lines
3.0 KiB
Markdown
---
|
||
id: 587d824b367417b2b2512c48
|
||
title: Використання Assert.isOK і Assert.isNotOK
|
||
challengeType: 2
|
||
forumTopicId: 301607
|
||
dashedName: use-assert-isok-and-assert-isnotok
|
||
---
|
||
|
||
# --description--
|
||
|
||
Нагадуємо, що цей проєкт будується на основі такого початкового проєкту на [ Replit ](https://replit.com/github/freeCodeCamp/boilerplate-mochachai) або клонується з [ GitHub](https://github.com/freeCodeCamp/boilerplate-mochachai/).
|
||
|
||
`isOk()` перевіряє правдиве значення, а `isNotOk()` перевіряє хибне значення.
|
||
|
||
Щоб дізнатися більше про правдиві й хибні значення, перейдіть на завдання [Хибний вибивало](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/falsy-bouncer).
|
||
|
||
# --instructions--
|
||
|
||
У `tests/1_unit-tests.js` тесті з позначкою `#3` у наборі `Basic Assertions` змініть кожне `assert` на `assert.isOk()` або `assert.isNotOk()`, щоб пройти тест (має мати значення `true`). Не змінюйте аргументи, передані до тверджень.
|
||
|
||
# --hints--
|
||
|
||
Всі тести повинні бути успішно пройдені.
|
||
|
||
```js
|
||
(getUserInput) =>
|
||
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=2').then(
|
||
(data) => {
|
||
assert.equal(data.state, 'passed');
|
||
},
|
||
(xhr) => {
|
||
throw new Error(xhr.responseText);
|
||
}
|
||
);
|
||
```
|
||
|
||
Потрібно обрати правильний метод для першого твердження – `isOk` у порівнянні з `isNotOk`.
|
||
|
||
```js
|
||
(getUserInput) =>
|
||
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=2').then(
|
||
(data) => {
|
||
assert.equal(data.assertions[0].method, 'isNotOk', 'Null is falsy');
|
||
},
|
||
(xhr) => {
|
||
throw new Error(xhr.responseText);
|
||
}
|
||
);
|
||
```
|
||
|
||
Потрібно обрати правильний метод для другого твердження – `isOk` у порівнянні з `isNotOk`.
|
||
|
||
```js
|
||
(getUserInput) =>
|
||
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=2').then(
|
||
(data) => {
|
||
assert.equal(data.assertions[1].method, 'isOk', 'A string is truthy');
|
||
},
|
||
(xhr) => {
|
||
throw new Error(xhr.responseText);
|
||
}
|
||
);
|
||
```
|
||
|
||
Потрібно обрати правильний метод для третього твердження – `isOk` у порівнянні з `isNotOk`.
|
||
|
||
```js
|
||
(getUserInput) =>
|
||
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=2').then(
|
||
(data) => {
|
||
assert.equal(data.assertions[2].method, 'isOk', 'true is truthy');
|
||
},
|
||
(xhr) => {
|
||
throw new Error(xhr.responseText);
|
||
}
|
||
);
|
||
```
|
||
|
||
# --solutions--
|
||
|
||
```js
|
||
/**
|
||
Backend challenges don't need solutions,
|
||
because they would need to be tested against a full working project.
|
||
Please check our contributing guidelines to learn more.
|
||
*/
|
||
```
|