2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
id: 587d824b367417b2b2512c48
|
2020-12-16 00:37:30 -07:00
|
|
|
|
title: 使用 Assert.isOk() 和 Assert.isNotOK()
|
2018-10-10 18:03:03 -04:00
|
|
|
|
challengeType: 2
|
2020-09-17 03:50:23 -07:00
|
|
|
|
forumTopicId: 301607
|
2018-10-10 18:03:03 -04:00
|
|
|
|
---
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --description--
|
|
|
|
|
|
|
|
|
|
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
|
2020-09-17 03:50:23 -07:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
`isOk()` 用来测试值是否为 `truthy`;`isNotOk()` 用来测试值是否为 `falsy`。 如果你想了解更多关于 truthy 和 falsy 值的内容,请参阅 [Falsy Bouncer](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/falsy-bouncer) 这道挑战题目。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --instructions--
|
2020-09-17 03:50:23 -07:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
使用 `assert.isOk()` 或 `assert.isNotOk()` 让测试通过。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
不应有未通过的测试
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
```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);
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
请选择正确的断言—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);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
请选择正确的断言—isOk 或 isNotOk
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
```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);
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
请选择正确的断言—isOk 或 isNotOk
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
|
(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);
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
|
# --solutions--
|
|
|
|
|
|