Files
freeCodeCamp/curriculum/challenges/chinese/06-quality-assurance/quality-assurance-and-testing-with-chai/use-assert.isok-and-assert.isnotok.md

57 lines
2.4 KiB
Markdown
Raw Normal View History

---
id: 587d824b367417b2b2512c48
challengeType: 2
forumTopicId: 301607
2020-10-01 17:54:21 +02:00
title: 使用 Assert.isOk() 和 Assert.isNotOK()
---
## Description
<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>isOk()</code> 用来测试值是否为 <code>truthy</code><code>isNotOk()</code> 用来测试值是否为 <code>falsy</code>
如果你想了解更多关于 truthy 和 falsy 值的内容,请参阅 <a href="https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/falsy-bouncer" target="_blank">Falsy Bouncer</a> 这道挑战题目。
</section>
## Instructions
<section id='instructions'>
使用 <code>assert.isOk()</code><code>assert.isNotOk()</code> 让测试通过。
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=2').then(data => {assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isOk 或 isNotOk
testString: 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); })
- text: 请选择正确的断言—isOk 或 isNotOk
testString: 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); })
- text: 请选择正确的断言—isOk 或 isNotOk
testString: 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); })
```
</section>
## Challenge Seed
<section id='challengeSeed'>
</section>
## Solution
<section id='solution'>
```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.
*/
```
</section>