102 lines
2.8 KiB
Markdown
102 lines
2.8 KiB
Markdown
---
|
|
id: 587d824b367417b2b2512c49
|
|
title: Testare la veridicità
|
|
challengeType: 2
|
|
forumTopicId: 301596
|
|
dashedName: test-for-truthiness
|
|
---
|
|
|
|
# --description--
|
|
|
|
Come promemoria, questo progetto verrà costruito a partire dalla seguente bozza su [Replit](https://replit.com/github/freeCodeCamp/boilerplate-mochachai), o clonato da [GitHub](https://github.com/freeCodeCamp/boilerplate-mochachai/).
|
|
|
|
`isTrue()` testa per il valore boleano `true` e `isNotTrue()` passa per qualsiasi cosa che non sia il valore booleano `true`.
|
|
|
|
```js
|
|
assert.isTrue(true, 'This will pass with the boolean value true');
|
|
assert.isTrue('true', 'This will NOT pass with the string value "true"');
|
|
assert.isTrue(1, 'This will NOT pass with the number value 1');
|
|
```
|
|
|
|
Esistono anche `isFalse()` e `isNotFalse()`, si comportano in maniera simile alle loro controparti con true tranne per il fatto che testano per il valore booleano `false`.
|
|
|
|
# --instructions--
|
|
|
|
All'interno di `tests/1_unit-tests.js` sotto il test etichettato con `#4` nella suite `Basic Assertions`, cambia ogni `assert` con `assert.isTrue` oppure `assert.isNotTrue` per fare passare il test (dovrebbe essere uguale a `true`). Non cambiare gli argomenti passati alle asserzioni.
|
|
|
|
# --hints--
|
|
|
|
Tutti i test dovrebbero essere superati.
|
|
|
|
```js
|
|
(getUserInput) =>
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=3').then(
|
|
(data) => {
|
|
assert.equal(data.state, 'passed');
|
|
},
|
|
(xhr) => {
|
|
throw new Error(xhr.responseText);
|
|
}
|
|
);
|
|
```
|
|
|
|
Dovresti scegliere il metodo corretto per la prima asserzione - `isTrue` oppure `isNotTrue`.
|
|
|
|
```js
|
|
(getUserInput) =>
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=3').then(
|
|
(data) => {
|
|
assert.equal(data.assertions[0].method, 'isTrue', 'True is true');
|
|
},
|
|
(xhr) => {
|
|
throw new Error(xhr.responseText);
|
|
}
|
|
);
|
|
```
|
|
|
|
Dovresti scegliere il metodo corretto per la seconda asserzione - `isTrue` oppure `isNotTrue`.
|
|
|
|
```js
|
|
(getUserInput) =>
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=3').then(
|
|
(data) => {
|
|
assert.equal(
|
|
data.assertions[1].method,
|
|
'isTrue',
|
|
'Double negation of a truthy value is true'
|
|
);
|
|
},
|
|
(xhr) => {
|
|
throw new Error(xhr.responseText);
|
|
}
|
|
);
|
|
```
|
|
|
|
Dovresti scegliere il metodo corretto per la terza asserzione - `isTrue` oppure `isNotTrue`.
|
|
|
|
```js
|
|
(getUserInput) =>
|
|
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=3').then(
|
|
(data) => {
|
|
assert.equal(
|
|
data.assertions[2].method,
|
|
'isNotTrue',
|
|
'A truthy object is not true - neither is a false one'
|
|
);
|
|
},
|
|
(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.
|
|
*/
|
|
```
|