2018-10-10 22:03:03 +00:00
---
id: 587d824b367417b2b2512c49
challengeType: 2
2020-08-15 23:13:26 +00:00
videoUrl: ''
2020-10-01 15:54:21 +00:00
title: 测试真实性
2018-10-10 22:03:03 +00:00
---
## Description
2020-09-17 10:50:23 +00:00
< section id = 'description' >
请注意,本项目在 < a href = "https://repl.it/github/freeCodeCamp/boilerplate-mochachai" > 这个 Repl.it 项目< / a > 的基础上进行开发。你也可以从 < a href = 'https://repl.it/github/freeCodeCamp/boilerplate-mochachai' > GitHub< / a > 上克隆。
< code > isTrue()< / code > 仅当给出的值为 Boolean 的 < code > true< / code > 时可以通过测试;< code > isNotTrue()< / code > 则会在给出除 < code > true< / code > 以外的值时通过测试。
```js
assert.isTrue(true, '可以通过,因为值的类型是布尔且值为 true');
assert.isTrue('true', '不能通过,因为值的类型是字符串);
assert.isTrue(1, '不过能通过,因为值是数字 1');
```
< code > isFalse()< / code > 和 < code > isNotFalse()< / code > 同样存在,表现与上面提到的两个方法类似。
< / section >
2018-10-10 22:03:03 +00:00
## Instructions
2020-09-17 10:50:23 +00:00
< section id = 'instructions' >
使用 < code > assert.isTrue()< / code > 或 < code > assert.isNotTrue()< / code > 让测试通过。
2018-10-10 22:03:03 +00:00
< / section >
## Tests
< section id = 'tests' >
```yml
tests:
2020-09-17 10:50:23 +00:00
- text: 不应有未通过的测试
2020-02-17 16:40:55 +00:00
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit& n=3').then(data => {assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
2020-09-17 10:50:23 +00:00
- text: 请选择正确的断言—isTrue 或 isNotTrue
2020-02-17 16:40:55 +00:00
testString: 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); })
2020-09-17 10:50:23 +00:00
- text: 请选择正确的断言—isTrue 或 isNotTrue
2020-02-17 16:40:55 +00:00
testString: 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); })
2020-09-17 10:50:23 +00:00
- text: 请选择正确的断言—isTrue 或 isNotTrue
2020-02-17 16:40:55 +00:00
testString: 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); })
2018-10-10 22:03:03 +00:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< / section >
## Solution
< section id = 'solution' >
```js
2020-09-17 10:50:23 +00:00
/**
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.
*/
2018-10-10 22:03:03 +00:00
```
2020-08-13 15:24:35 +00:00
2020-09-17 10:50:23 +00:00
< / section >