2021-06-15 00:49:18 -07:00
---
id: 587d824a367417b2b2512c46
2021-07-19 16:05:37 +05:30
title: Imparare come funzionano le asserzioni Javascript
2021-06-15 00:49:18 -07:00
challengeType: 2
forumTopicId: 301589
dashedName: learn-how-javascript-assertions-work
---
# --description--
2021-07-19 16:05:37 +05:30
Lavorare su queste sfide ti porterà a scrivere il tuo codice utilizzando uno dei seguenti metodi:
2021-06-15 00:49:18 -07:00
2021-07-19 16:05:37 +05:30
- Clonare [questo repository GitHub ](https://github.com/freeCodeCamp/boilerplate-mochachai/ ) e completare queste sfide localmente.
- Usare [la nostra bozza di progetto su Replit ](https://replit.com/github/freeCodeCamp/boilerplate-mochachai ) per completare queste sfide.
- Usare un costruttore di siti a tua scelta per completare il progetto. Assicurati di incorporare tutti i file del nostro repository GitHub.
2021-06-15 00:49:18 -07:00
2021-07-19 16:05:37 +05:30
Quando hai finito, assicurati che una demo funzionante del tuo progetto sia ospitata in qualche percorso pubblico. Quindi invia l'URL nel campo `Solution Link` .
2021-06-15 00:49:18 -07:00
# --instructions--
2021-07-19 16:05:37 +05:30
All'interno di `tests/1_unit-tests.js` , sotto il test etichettato con `#1` , nella suite `Basic Assertions` , cambia ogni asserzione `assert` in `assert.isNull` o `assert.isNotNull` per far superare il test (dovrebbe risultare `true` ). Non alterare gli argomenti passati alle asserzioni.
2021-06-15 00:49:18 -07:00
# --hints--
2021-07-19 16:05:37 +05:30
Tutti i test dovrebbero essere superati.
2021-06-15 00:49:18 -07:00
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit& n=0').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
2021-07-19 16:05:37 +05:30
Dovresti scegliere il metodo corretto per la prima asserzione - `isNull` oppure `isNotNull` .
2021-06-15 00:49:18 -07:00
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit& n=0').then(
(data) => {
assert.equal(data.assertions[0].method, 'isNull', 'Null is null');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
2021-07-19 16:05:37 +05:30
Dovresti scegliere il metodo corretto per la seconda asserzione - `isNull` oppure `isNotNull` .
2021-06-15 00:49:18 -07:00
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit& n=0').then(
(data) => {
assert.equal(data.assertions[1].method, 'isNotNull', '1 is not null');
},
(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.
*/
```