chore(learn): Applied MDX format to Chinese curriculum files (#40462)

This commit is contained in:
Randell Dawson
2020-12-16 00:37:30 -07:00
committed by GitHub
parent 873fce02a2
commit 9ce4a02a41
1665 changed files with 58741 additions and 88042 deletions

View File

@@ -1,52 +1,71 @@
---
id: 587d824c367417b2b2512c4c
title: 用 Assert.deepEqual() 和 Assert.notDeepEqual() 断言深度相等
challengeType: 2
forumTopicId: 301587
title: 用 Assert.deepEqual() 和 Assert.notDeepEqual() 断言深度相等
---
## 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>deepEqual()</code> 断言两个对象是否 deep equal
</section>
# --description--
## Instructions
<section id='instructions'>
使用 <code>assert.deepEqual()</code> 或者 <code>assert.notDeepEqual()</code> 来让测试通过。
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
</section>
`deepEqual()` 断言两个对象是否 deep equal
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=6').then(data => {assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—deepEqual 或 notDeepEqual
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=6').then(data => { assert.equal(data.assertions[0].method, 'deepEqual', 'The order of the keys does not matter'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—deepEqual 或 notDeepEqual
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=6').then(data => { assert.equal(data.assertions[1].method, 'notDeepEqual', 'The position of elements within an array does matter'); }, xhr => { throw new Error(xhr.responseText); })
使用 `assert.deepEqual()` 或者 `assert.notDeepEqual()` 来让测试通过。
```
# --hints--
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=6').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—deepEqual 或 notDeepEqual
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=6').then(
(data) => {
assert.equal(
data.assertions[0].method,
'deepEqual',
'The order of the keys does not matter'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—deepEqual 或 notDeepEqual
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=6').then(
(data) => {
assert.equal(
data.assertions[1].method,
'notDeepEqual',
'The position of elements within an array does matter'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,55 +1,101 @@
---
id: 587d824c367417b2b2512c4d
title: 比较两个元素的属性
challengeType: 2
forumTopicId: 301588
title: 比较两个元素的属性
---
## 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> 上克隆。
</section>
# --description--
## Instructions
<section id='instructions'>
使用 <code>assert.isAbove()</code>(大于)或者 <code>assert.isAtMost()</code>(小于或等于)来让测试通过。
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
</section>
# --instructions--
## Tests
<section id='tests'>
使用 `assert.isAbove()`(大于)或者 `assert.isAtMost()`(小于或等于)来让测试通过。
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(data => {assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isAbove 或 isAtMost
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(data => { assert.equal(data.assertions[0].method, 'isAtMost', '5 is at most (<=) 5'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isAbove 或 isAtMost
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(data => { assert.equal(data.assertions[1].method, 'isAbove', '1 is greater than 0'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isAbove 或 isAtMost
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(data => { assert.equal(data.assertions[2].method, 'isAbove', 'Math.PI = 3.14159265 is greater than 3'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isAbove 或 isAtMost
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(data => { assert.equal(data.assertions[3].method, 'isAtMost', '1 - Math.random() is > 0 and <= 1. It is atMost 1 !'); }, xhr => { throw new Error(xhr.responseText); })
# --hints--
```
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—isAbove 或 isAtMost
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(
(data) => {
assert.equal(
data.assertions[0].method,
'isAtMost',
'5 is at most (<=) 5'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—isAbove 或 isAtMost
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(
(data) => {
assert.equal(data.assertions[1].method, 'isAbove', '1 is greater than 0');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—isAbove 或 isAtMost
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(
(data) => {
assert.equal(
data.assertions[2].method,
'isAbove',
'Math.PI = 3.14159265 is greater than 3'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—isAbove 或 isAtMost
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=7').then(
(data) => {
assert.equal(
data.assertions[3].method,
'isAtMost',
'1 - Math.random() is > 0 and <= 1. It is atMost 1 !'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,51 +1,61 @@
---
id: 587d824a367417b2b2512c46
title: 了解 JavaScript 断言是如何使用的
challengeType: 2
forumTopicId: 301589
title: 了解 JavaScript 断言是如何使用的
---
## 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> 上克隆。
# --description--
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
# --instructions--
## Instructions
<section id='instructions'>
使用 assert.isNull() 或 assert.isNotNull() 来让测试通过。
</section>
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=0').then(data => {assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isNull 或 isNotNull
testString: 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); })
- text: You should choose the right assertion - isNull vs. isNotNull.
testString: 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); })
```
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=0').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—isNull 或 isNotNull
```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);
}
);
```
You should choose the right assertion - isNull vs. isNotNull.
```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--

View File

@@ -1,15 +1,17 @@
---
id: 587d824f367417b2b2512c5a
title: 使用 Chai-HTTP 测试 API 响应结果 (3)—PUT 方法
challengeType: 2
forumTopicId: 301590
title: 使用 Chai-HTTP 测试 API 响应结果 (3)—PUT 方法
---
## 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> 上克隆。
# --description--
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
接下来,我们将了解如何使用请求的 payloadbody发送数据。
我们需要测试一个 PUT 请求,<code>'/travellers'</code> 接收如下的 JSON 对象:
我们需要测试一个 PUT 请求,`'/travellers'` 接收如下的 JSON 对象:
```json
{
@@ -18,7 +20,7 @@ title: 使用 Chai-HTTP 测试 API 响应结果 (3)—PUT 方法
```
响应数据如下:
```json
{
"name": [first name], "surname": [last name], "dates": [birth - death years]
@@ -27,56 +29,97 @@ title: 使用 Chai-HTTP 测试 API 响应结果 (3)—PUT 方法
更多细节请查看服务器代码。
</section>
# --instructions--
## Instructions
<section id='instructions'>
发送 <br>
发送
```json
{
"surname": "Colombo"
}
```
替换 <code>assert.fail()</code> 使测试通过。
分别测试 1) <code>status</code>2) <code>type</code>3) <code>body.name</code>4) <code>body.surname</code>
请按照以上顺序书写断言,顺序错误会影响此挑战的判定。
</section>
## Tests
<section id='tests'>
替换 `assert.fail()` 使测试通过。 分别测试 1) `status`2) `type`3) `body.name`4) `body.surname` 请按照以上顺序书写断言,顺序错误会影响此挑战的判定。
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=2').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 你需要测试 'res.status' 是否为 200
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=2').then(data => { assert.equal(data.assertions[0].method, 'equal'); assert.equal(data.assertions[0].args[0], 'res.status'); assert.equal(data.assertions[0].args[1], '200');}, xhr => { throw new Error(xhr.responseText); })
- text: 你需要测试 'res.type' 是否为 'application/json'
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=2').then(data => { assert.equal(data.assertions[1].method, 'equal'); assert.equal(data.assertions[1].args[0], 'res.type'); assert.match(data.assertions[1].args[1], /('|")application\/json\1/);}, xhr => { throw new Error(xhr.responseText); })
- text: 你需要测试 'res.body.name' 是否为 'Cristoforo'
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=2').then(data => { assert.equal(data.assertions[2].method, 'equal'); assert.equal(data.assertions[2].args[0], 'res.body.name'); assert.match(data.assertions[2].args[1], /('|")Cristoforo\1/);}, xhr => { throw new Error(xhr.responseText); })
- text: 你需要测试 'res.body.surname' 是否为 'Colombo'
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=2').then(data => { assert.equal(data.assertions[3].method, 'equal'); assert.equal(data.assertions[3].args[0], 'res.body.surname'); assert.match(data.assertions[3].args[1], /('|")Colombo\1/);}, xhr => { throw new Error(xhr.responseText); })
# --hints--
```
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=2').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
你需要测试 'res.status' 是否为 200
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=2').then(
(data) => {
assert.equal(data.assertions[0].method, 'equal');
assert.equal(data.assertions[0].args[0], 'res.status');
assert.equal(data.assertions[0].args[1], '200');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
你需要测试 'res.type' 是否为 'application/json'
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=2').then(
(data) => {
assert.equal(data.assertions[1].method, 'equal');
assert.equal(data.assertions[1].args[0], 'res.type');
assert.match(data.assertions[1].args[1], /('|")application\/json\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
你需要测试 'res.body.name' 是否为 'Cristoforo'
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=2').then(
(data) => {
assert.equal(data.assertions[2].method, 'equal');
assert.equal(data.assertions[2].args[0], 'res.body.name');
assert.match(data.assertions[2].args[1], /('|")Cristoforo\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
你需要测试 'res.body.surname' 是否为 'Colombo'
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=2').then(
(data) => {
assert.equal(data.assertions[3].method, 'equal');
assert.equal(data.assertions[3].args[0], 'res.body.surname');
assert.match(data.assertions[3].args[1], /('|")Colombo\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,19 +1,18 @@
---
id: 587d824f367417b2b2512c5b
title: 使用 Chai-HTTP 测试 API 响应结果 (4)—PUT 方法
challengeType: 2
forumTopicId: 301591
title: 使用 Chai-HTTP 测试 API 响应结果 (4)—PUT 方法
---
## 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> 上克隆。
# --description--
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
这个练习与上一个类似,我们详细看看。
</section>
# --instructions--
## Instructions
<section id='instructions'>
发送
```json
@@ -22,45 +21,87 @@ title: 使用 Chai-HTTP 测试 API 响应结果 (4)—PUT 方法
}
```
替换 assert.fail(),使测试通过。
分别测试 1) <code>status</code>2) <code>type</code>3) <code>body.name</code>4) <code>body.surname</code>
请按照以上顺序书写断言,顺序错误会影响此挑战的判定。
</section>
替换 assert.fail(),使测试通过。 分别测试 1) `status`2) `type`3) `body.name`4) `body.surname` 请按照以上顺序书写断言,顺序错误会影响此挑战的判定。
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 你需要测试 'res.status' 是否为 200
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(data => { assert.equal(data.assertions[0].method, 'equal'); assert.equal(data.assertions[0].args[0], 'res.status'); assert.equal(data.assertions[0].args[1], '200');}, xhr => { throw new Error(xhr.responseText); })
- text: 你需要测试 'res.type' 是否为 'application/json'
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(data => { assert.equal(data.assertions[1].method, 'equal'); assert.equal(data.assertions[1].args[0], 'res.type'); assert.match(data.assertions[1].args[1], /('|")application\/json\1/);}, xhr => { throw new Error(xhr.responseText); })
- text: 你需要测试 'res.body.name' 是否为 'Giovanni'
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(data => { assert.equal(data.assertions[2].method, 'equal'); assert.equal(data.assertions[2].args[0], 'res.body.name'); assert.match(data.assertions[2].args[1], /('|")Giovanni\1/);}, xhr => { throw new Error(xhr.responseText); })
- text: 你需要测试 'res.body.surname' 是否为 'da Verrazzano'
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(data => { assert.equal(data.assertions[3].method, 'equal'); assert.equal(data.assertions[3].args[0], 'res.body.surname'); assert.match(data.assertions[3].args[1], /('|")da Verrazzano\1/);}, 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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
你需要测试 'res.status' 是否为 200
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(
(data) => {
assert.equal(data.assertions[0].method, 'equal');
assert.equal(data.assertions[0].args[0], 'res.status');
assert.equal(data.assertions[0].args[1], '200');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
你需要测试 'res.type' 是否为 'application/json'
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(
(data) => {
assert.equal(data.assertions[1].method, 'equal');
assert.equal(data.assertions[1].args[0], 'res.type');
assert.match(data.assertions[1].args[1], /('|")application\/json\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
你需要测试 'res.body.name' 是否为 'Giovanni'
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(
(data) => {
assert.equal(data.assertions[2].method, 'equal');
assert.equal(data.assertions[2].args[0], 'res.body.name');
assert.match(data.assertions[2].args[1], /('|")Giovanni\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
你需要测试 'res.body.surname' 是否为 'da Verrazzano'
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=3').then(
(data) => {
assert.equal(data.assertions[3].method, 'equal');
assert.equal(data.assertions[3].args[0], 'res.body.surname');
assert.match(data.assertions[3].args[1], /('|")da Verrazzano\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,52 +1,67 @@
---
id: 587d824f367417b2b2512c59
title: 使用 Chai-HTTP 进行 API 功能测试 (2)
challengeType: 2
forumTopicId: 301592
title: 使用 Chai-HTTP 进行 API 功能测试 (2)
---
## 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> 上克隆。
# --description--
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
## Instructions
<section id='instructions'>
测试 status 和 <code>text.response</code>。替换 <code>assert.fail()</code> 使测试通过。
请把 name 的值添加到 query 结尾:<code>?name=&ltyour_name&gt</code>,后端将会返回 <code>'hello &ltyour_name&gt'</code>
</section>
# --instructions--
## Tests
<section id='tests'>
测试 status 和 `text.response`。替换 `assert.fail()` 使测试通过。
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=1').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 你需要测试 'res.status' 是否为 200
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=1').then(data => { assert.equal(data.assertions[0].method, 'equal'); assert.equal(data.assertions[0].args[0], 'res.status'); assert.equal(data.assertions[0].args[1], '200');}, xhr => { throw new Error(xhr.responseText); })
- text: 你需要测试 'res.text' 是否为 'hello Guest'
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=1').then(data => { assert.equal(data.assertions[1].method, 'equal'); assert.equal(data.assertions[1].args[0], 'res.text'); assert.match(data.assertions[1].args[1], /hello [\w\d_-]/);}, xhr => { throw new Error(xhr.responseText); })
请把 name 的值添加到 query 结尾:`?name=<your_name>`,后端将会返回 `'hello <your_name>'`
```
# --hints--
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=1').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
你需要测试 'res.status' 是否为 200
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=1').then(
(data) => {
assert.equal(data.assertions[0].method, 'equal');
assert.equal(data.assertions[0].args[0], 'res.status');
assert.equal(data.assertions[0].args[1], '200');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
你需要测试 'res.text' 是否为 'hello Guest'
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=1').then(
(data) => {
assert.equal(data.assertions[1].method, 'equal');
assert.equal(data.assertions[1].args[0], 'res.text');
assert.match(data.assertions[1].args[1], /hello [\w\d_-]/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,52 +1,67 @@
---
id: 587d824e367417b2b2512c58
title: 使用 Chai-HTTP 进行 API 功能测试 (1)
challengeType: 2
forumTopicId: 301593
title: 使用 Chai-HTTP 进行 API 功能测试 (1)
---
## 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> 上克隆。
# --description--
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
# --instructions--
测试 status 和 `text.response`。替换 `assert.fail()` 使测试通过。
## Instructions
<section id='instructions'>
测试 status 和 <code>text.response</code>。替换 <code>assert.fail()</code> 使测试通过。
不要在 query 中传入 name后端将会返回 "hello Guest"。
</section>
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=0').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 你需要测试 'res.status' 是否为 200
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=0').then(data => { assert.equal(data.assertions[0].method, 'equal'); assert.equal(data.assertions[0].args[0], 'res.status'); assert.equal(data.assertions[0].args[1], '200');}, xhr => { throw new Error(xhr.responseText); })
- text: 你需要测试 'res.text' 是否为 'hello Guest'
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=0').then(data => { assert.equal(data.assertions[1].method, 'equal'); assert.equal(data.assertions[1].args[0], 'res.text'); assert.match(data.assertions[1].args[1], /('|")hello Guest\1/);}, 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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=0').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
你需要测试 'res.status' 是否为 200
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=0').then(
(data) => {
assert.equal(data.assertions[0].method, 'equal');
assert.equal(data.assertions[0].args[0], 'res.status');
assert.equal(data.assertions[0].args[1], '200');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
你需要测试 'res.text' 是否为 'hello Guest'
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=0').then(
(data) => {
assert.equal(data.assertions[1].method, 'equal');
assert.equal(data.assertions[1].args[0], 'res.text');
assert.match(data.assertions[1].args[1], /('|")hello Guest\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,56 +1,97 @@
---
id: 587d8250367417b2b2512c5d
title: 使用 headless 浏览器运行功能测试 (2)
challengeType: 2
forumTopicId: 301594
title: 使用 headless 浏览器运行功能测试 (2)
---
## 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> 上克隆。
# --description--
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
# --instructions--
## Instructions
<section id='instructions'>
此挑战与之前的挑战十分类似。
请阅读此挑战给出的代码指引,按顺序书写断言。顺序错误会影响此挑战的判定。
</section>
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: Headless browser 应成功执行请求
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(data => { assert.equal(data.assertions[0].method, 'browser.success'); }, xhr => { throw new Error(xhr.responseText); })
- text: 元素 'span#name' 中的文字应为 'Amerigo'.
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(data => { assert.equal(data.assertions[1].method, 'browser.text'); assert.match(data.assertions[1].args[0], /('|")span#name\1/); assert.match(data.assertions[1].args[1], /('|")Amerigo\1/);}, xhr => { throw new Error(xhr.responseText); })
- text: 元素 'span#surname' 中的文字应为 'Vespucci'.
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(data => { assert.equal(data.assertions[2].method, 'browser.text'); assert.match(data.assertions[2].args[0], /('|")span#surname\1/); assert.match(data.assertions[2].args[1], /('|")Vespucci\1/);}, xhr => { throw new Error(xhr.responseText); })
- text: 元素 'span#dates' 应存在,并且只有一个
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(data => { assert.equal(data.assertions[3].method, 'browser.element'); assert.match(data.assertions[3].args[0], /('|")span#dates\1/); assert.equal(data.assertions[3].args[1], 1);}, 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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
Headless browser 应成功执行请求
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(
(data) => {
assert.equal(data.assertions[0].method, 'browser.success');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
元素 'span#name' 中的文字应为 'Amerigo'.
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(
(data) => {
assert.equal(data.assertions[1].method, 'browser.text');
assert.match(data.assertions[1].args[0], /('|")span#name\1/);
assert.match(data.assertions[1].args[1], /('|")Amerigo\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
元素 'span#surname' 中的文字应为 'Vespucci'.
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(
(data) => {
assert.equal(data.assertions[2].method, 'browser.text');
assert.match(data.assertions[2].args[0], /('|")span#surname\1/);
assert.match(data.assertions[2].args[1], /('|")Vespucci\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
元素 'span#dates' 应存在,并且只有一个
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=5').then(
(data) => {
assert.equal(data.assertions[3].method, 'browser.element');
assert.match(data.assertions[3].args[0], /('|")span#dates\1/);
assert.equal(data.assertions[3].args[1], 1);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,58 +1,101 @@
---
id: 587d824f367417b2b2512c5c
title: 使用 headless 浏览器运行功能测试 (1)
challengeType: 2
forumTopicId: 301595
title: 使用 headless 浏览器运行功能测试 (1)
---
## 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> 上克隆。
# --description--
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
在这一项挑战中,我们将会使用 Headless Browser无头浏览器模拟人机交互。
<a href="https://en.wikipedia.org/wiki/Headless_browser">无头浏览器</a> 是一种没有图形用户界面的浏览器。这类工具对网页调试特别有效,因为它们可以跟普通浏览器一样理解和渲染 HTMLCSS 和 JavaScript。
</section>
[无头浏览器](https://en.wikipedia.org/wiki/Headless_browser) 是一种没有图形用户界面的浏览器。这类工具对网页调试特别有效,因为它们可以跟普通浏览器一样理解和渲染 HTMLCSS 和 JavaScript。
# --instructions--
在这个挑战中,我们将使用 Zombie.JS。它是一款完全基于 JS 的轻量级浏览器,不需要安装其他二进制文件。这个特性让它轻松地在如 Repl.it 的环境下使用。除此之外还有很多更强大的Headless Browser 选项。
## Instructions
<section id='instructions'>
在这个挑战中,我们将使用 Zombie.JS。它是一款完全基于 JS 的轻量级浏览器,不需要安装其他二进制文件。这个特性让它轻松地在如 Repl.it 的环境下使用。除此之外还有很多更强大的Headless Browser 选项。<br>
请阅读此挑战给出的代码指引,按顺序书写断言。顺序错误会影响此挑战的判定。
</section>
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=4').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: Headless browser 应成功执行请求
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=4').then(data => { assert.equal(data.assertions[0].method, 'browser.success'); }, xhr => { throw new Error(xhr.responseText); })
- text: 元素 'span#name' 中的文字应为 'Cristoforo'
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=4').then(data => { assert.equal(data.assertions[1].method, 'browser.text'); assert.match(data.assertions[1].args[0], /('|")span#name\1/); assert.match(data.assertions[1].args[1], /('|")Cristoforo\1/);}, xhr => { throw new Error(xhr.responseText); })
- text: 元素 'span#surname' 中的文字应为 'Colombo'.
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=4').then(data => { assert.equal(data.assertions[2].method, 'browser.text'); assert.match(data.assertions[2].args[0], /('|")span#surname\1/); assert.match(data.assertions[2].args[1], /('|")Colombo\1/);}, xhr => { throw new Error(xhr.responseText); })
- text: 元素 'span#dates' 应存在,并且只有一个
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=functional&n=4').then(data => { assert.equal(data.assertions[3].method, 'browser.element'); assert.match(data.assertions[3].args[0], /('|")span#dates\1/); assert.equal(data.assertions[3].args[1], 1);}, 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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=4').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
Headless browser 应成功执行请求
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=4').then(
(data) => {
assert.equal(data.assertions[0].method, 'browser.success');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
元素 'span#name' 中的文字应为 'Cristoforo'
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=4').then(
(data) => {
assert.equal(data.assertions[1].method, 'browser.text');
assert.match(data.assertions[1].args[0], /('|")span#name\1/);
assert.match(data.assertions[1].args[1], /('|")Cristoforo\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
元素 'span#surname' 中的文字应为 'Colombo'.
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=4').then(
(data) => {
assert.equal(data.assertions[2].method, 'browser.text');
assert.match(data.assertions[2].args[0], /('|")span#surname\1/);
assert.match(data.assertions[2].args[1], /('|")Colombo\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
元素 'span#dates' 应存在,并且只有一个
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=4').then(
(data) => {
assert.equal(data.assertions[3].method, 'browser.element');
assert.match(data.assertions[3].args[0], /('|")span#dates\1/);
assert.equal(data.assertions[3].args[1], 1);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -0,0 +1,115 @@
---
id: 5f8884f4c46685731aabfc41
title: Simulate Actions Using a Headless Browser
challengeType: 2
---
# --description--
As a reminder, this project is being built upon the following starter project on [Repl.it](https://repl.it/github/freeCodeCamp/boilerplate-mochachai), or cloned from [GitHub](https://github.com/freeCodeCamp/boilerplate-mochachai/).
# --instructions--
Within `tests/2_functional-tests.js`, in the `'submit "surname" : "Vespucci" - write your e2e test...'` test (`// #6`), automate filling-in and submitting the form from scratch:
1. Fill in the form with the `surname` of `Vespucci`
2. Submit it pressing `'submit'` button
Within the callback:
1. assert that status is `200`
2. assert that the text inside the element `span#name` is `'Amerigo'`
3. assert that the text inside the element `span#surname` is `'Vespucci'`
4. assert that the element(s) `span#dates` exist and their count is `1`
Do not forget to to remove the `assert.fail()` call.
# --hints--
All tests should pass.
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=6').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
You should assert that the headless browser request succeeded.
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=6').then(
(data) => {
assert.equal(data.assertions[0].method, 'browser.success');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
You should assert that the text inside the element 'span#name' is 'Amerigo'.
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=6').then(
(data) => {
assert.equal(data.assertions[1].method, 'browser.text');
assert.match(data.assertions[1].args[0], /('|")span#name\1/);
assert.match(data.assertions[1].args[1], /('|")Amerigo\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
You should assert that the text inside the element 'span#surname' is 'Vespucci'.
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=6').then(
(data) => {
assert.equal(data.assertions[2].method, 'browser.text');
assert.match(data.assertions[2].args[0], /('|")span#surname\1/);
assert.match(data.assertions[2].args[1], /('|")Vespucci\1/);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
You should assert that the element 'span#dates' exist and its count is 1.
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=functional&n=6').then(
(data) => {
assert.equal(data.assertions[3].method, 'browser.element');
assert.match(data.assertions[3].args[0], /('|")span#dates\1/);
assert.equal(data.assertions[3].args[1], 1);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --seed--
# --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.
*/
```

View File

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

View File

@@ -1,54 +1,71 @@
---
id: 587d824d367417b2b2512c53
title: 测试字符串是否包含子字符串
challengeType: 2
forumTopicId: 301597
title: 测试字符串是否包含子字符串
---
## 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> 上克隆。
# --description--
<code>include()</code><code>notInclude()</code> 同样可以用于字符串
<code>include()</code> 用于断言字符串中包含某个子字符串。
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆
## Instructions
<section id='instructions'>
使用 <code>assert.include()</code><code>assert.notInclude()</code> 让测试通过。
`include()``notInclude()` 同样可以用于字符串。 `include()` 用于断言字符串中包含某个子字符串。
</section>
# --instructions--
## Tests
<section id='tests'>
使用 `assert.include()``assert.notInclude()` 让测试通过。
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=13').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—include 或 notInclude
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=13').then(data => { assert.equal(data.assertions[0].method, 'include', '\'Arrow\' contains \'row\'...'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—include 或 notInclude
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=13').then(data => { assert.equal(data.assertions[1].method, 'notInclude', '... a \'dart\' doesn\'t contain a \'queue\''); }, xhr => { throw new Error(xhr.responseText); })
# --hints--
```
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=13').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—include 或 notInclude
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=13').then(
(data) => {
assert.equal(
data.assertions[0].method,
'include',
"'Arrow' contains 'row'..."
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—include 或 notInclude
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=13').then(
(data) => {
assert.equal(
data.assertions[1].method,
'notInclude',
"... a 'dart' doesn't contain a 'queue'"
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,54 +1,75 @@
---
id: 587d824c367417b2b2512c4f
title: 测试某个值是否在特定范围内
challengeType: 2
forumTopicId: 301598
title: 测试某个值是否在特定范围内
---
## 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> 上克隆。
# --description--
<code>.approximately(actual, expected, delta, [message])</code>
断言待测试的值处于 <code>expected</code> +/- <code>delta</code> 的范围内。
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
`.approximately(actual, expected, delta, [message])` 断言待测试的值处于 `expected` +/- `delta` 的范围内。
# --instructions--
使用 `assert.approximately()` 让测试通过。
## Instructions
<section id='instructions'>
使用 <code>assert.approximately()</code> 让测试通过。
选择最小范围(第三个参数)来通过所有测试。它应该小于 1。
</section>
## Tests
<section id='tests'>
# --hints--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=9').then(data => {assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 你应使用 approximately(actual, expected, range) 并选择正确的范围
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=9').then(data => { assert.equal(data.assertions[0].method, 'approximately'); assert.equal(data.assertions[0].args[2], 0.5, 'weirdNumbers(0.5) is in the range (0.5, 1.5]. It\'s within 1 +/- 0.5'); }, xhr => { throw new Error(xhr.responseText); })
- text: 你应使用 approximately(actual, expected, range) 并选择正确的范围
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=9').then(data => { assert.equal(data.assertions[1].method, 'approximately'); assert.equal(data.assertions[1].args[2], 0.8, 'weirdNumbers(0.2) is in the range (0.2, 1.2]. It\'s within 1 +/- 0.8'); }, 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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=9').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
你应使用 approximately(actual, expected, range) 并选择正确的范围
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=9').then(
(data) => {
assert.equal(data.assertions[0].method, 'approximately');
assert.equal(
data.assertions[0].args[2],
0.5,
"weirdNumbers(0.5) is in the range (0.5, 1.5]. It's within 1 +/- 0.5"
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
你应使用 approximately(actual, expected, range) 并选择正确的范围
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=9').then(
(data) => {
assert.equal(data.assertions[1].method, 'approximately');
assert.equal(
data.assertions[1].args[2],
0.8,
"weirdNumbers(0.2) is in the range (0.2, 1.2]. It's within 1 +/- 0.8"
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,53 +1,85 @@
---
id: 587d824d367417b2b2512c52
title: 测试某个值是否为字符串
challengeType: 2
forumTopicId: 301599
title: 测试某个值是否为字符串
---
## 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>isString</code><code>isNotString</code> 断言一个值是否为字符串。
</section>
# --description--
## Instructions
<section id='instructions'>
使用 <code>assert.isString()</code><code>assert.isNotString()</code> 让所有测试通过。
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
## Tests
<section id='tests'>
`isString``isNotString` 断言一个值是否为字符串。
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=12').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isString 或 isNotString
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=12').then(data => { assert.equal(data.assertions[0].method, 'isNotString', 'A float number is not a string'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isString 或 isNotString
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=12').then(data => { assert.equal(data.assertions[1].method, 'isString', 'environment vars are strings (or undefined)'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isString 或 isNotString
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=12').then(data => { assert.equal(data.assertions[2].method, 'isString', 'A JSON is a string'); }, xhr => { throw new Error(xhr.responseText); })
# --instructions--
```
使用 `assert.isString()``assert.isNotString()` 让所有测试通过。
</section>
# --hints--
## 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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=12').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—isString 或 isNotString
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=12').then(
(data) => {
assert.equal(
data.assertions[0].method,
'isNotString',
'A float number is not a string'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—isString 或 isNotString
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=12').then(
(data) => {
assert.equal(
data.assertions[1].method,
'isString',
'environment vars are strings (or undefined)'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—isString 或 isNotString
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=12').then(
(data) => {
assert.equal(data.assertions[2].method, 'isString', 'A JSON is a string');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,50 +1,69 @@
---
id: 587d824d367417b2b2512c50
title: 测试某个值是否为数组
challengeType: 2
forumTopicId: 301600
title: 测试某个值是否为数组
---
## 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> 上克隆。
</section>
# --description--
## Instructions
<section id='instructions'>
使用 <code>assert.isArray()</code><code>assert.isNotArray()</code> 让所有测试通过。
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=10').then(data => {assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isArray 或 isNotArray
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=10').then(data => { assert.equal(data.assertions[0].method, 'isArray', 'String.prototype.split() returns an Array'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isArray 或 isNotArray
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=10').then(data => { assert.equal(data.assertions[1].method, 'isNotArray', 'Array.prototype.indexOf() returns a number'); }, xhr => { throw new Error(xhr.responseText); })
使用 `assert.isArray()``assert.isNotArray()` 让所有测试通过。
```
# --hints--
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=10').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—isArray 或 isNotArray
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=10').then(
(data) => {
assert.equal(
data.assertions[0].method,
'isArray',
'String.prototype.split() returns an Array'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—isArray 或 isNotArray
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=10').then(
(data) => {
assert.equal(
data.assertions[1].method,
'isNotArray',
'Array.prototype.indexOf() returns a number'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,58 +1,125 @@
---
id: 587d824e367417b2b2512c56
title: 测试值是否为特定数据结构类型
challengeType: 2
forumTopicId: 301601
title: 测试值是否为特定数据结构类型
---
## 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>#typeOf</code> 断言一个值的类型符合给定的类型,这个类型与 <code>Object.prototype.toString</code> 一致。
# --description--
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
## Instructions
<section id='instructions'>
使用 <code>assert.typeOf()</code><code>assert.notTypeOf()</code> 让所有测试通过。
</section>
`#typeOf` 断言一个值的类型符合给定的类型,这个类型与 `Object.prototype.toString` 一致。
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=16').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—typeOf 或 notTypeOf
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=16').then(data => { assert.equal(data.assertions[0].method, 'typeOf', 'myCar is typeOf Object'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—typeOf 或 notTypeOf
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=16').then(data => { assert.equal(data.assertions[1].method, 'typeOf', 'Car.model is a String'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—typeOf 或 notTypeOf
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=16').then(data => { assert.equal(data.assertions[2].method, 'notTypeOf', 'Plane.wings is a Number (not a String)'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—typeOf 或 notTypeOf
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=16').then(data => { assert.equal(data.assertions[3].method, 'typeOf', 'Plane.engines is an Array'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—typeOf 或 notTypeOf
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=16').then(data => { assert.equal(data.assertions[4].method, 'typeOf', 'Car.wheels is a Number'); }, xhr => { throw new Error(xhr.responseText); })
使用 `assert.typeOf()``assert.notTypeOf()` 让所有测试通过。
```
# --hints--
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=16').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—typeOf 或 notTypeOf
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=16').then(
(data) => {
assert.equal(
data.assertions[0].method,
'typeOf',
'myCar is typeOf Object'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—typeOf 或 notTypeOf
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=16').then(
(data) => {
assert.equal(
data.assertions[1].method,
'typeOf',
'Car.model is a String'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—typeOf 或 notTypeOf
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=16').then(
(data) => {
assert.equal(
data.assertions[2].method,
'notTypeOf',
'Plane.wings is a Number (not a String)'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—typeOf 或 notTypeOf
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=16').then(
(data) => {
assert.equal(
data.assertions[3].method,
'typeOf',
'Plane.engines is an Array'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—typeOf 或 notTypeOf
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=16').then(
(data) => {
assert.equal(
data.assertions[4].method,
'typeOf',
'Car.wheels is a Number'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,53 +1,87 @@
---
id: 587d824b367417b2b2512c47
title: 测试变量或函数是否已定义
challengeType: 2
forumTopicId: 301602
title: 测试变量或函数是否已定义
---
## 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> 上克隆。
# --description--
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
## Instructions
<section id='instructions'>
使用 <code>assert.isDefined()</code><code>assert.isUndefined()</code> 让测试通过。
</section>
# --instructions--
## Tests
<section id='tests'>
使用 `assert.isDefined()``assert.isUndefined()` 让测试通过。
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=1').then(data => {assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—idDefined 或 idUndefined
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=1').then(data => { assert.equal(data.assertions[0].method, 'isDefined', 'Null is not undefined'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—idDefined 或 idUndefined
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=1').then(data => { assert.equal(data.assertions[1].method, 'isUndefined', 'Undefined is undefined'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—idDefined 或 idUndefined
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=1').then(data => { assert.equal(data.assertions[2].method, 'isDefined', 'A string is not undefined'); }, xhr => { throw new Error(xhr.responseText); })
# --hints--
```
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=1').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—idDefined 或 idUndefined
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=1').then(
(data) => {
assert.equal(
data.assertions[0].method,
'isDefined',
'Null is not undefined'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—idDefined 或 idUndefined
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=1').then(
(data) => {
assert.equal(
data.assertions[1].method,
'isUndefined',
'Undefined is undefined'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—idDefined 或 idUndefined
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=1').then(
(data) => {
assert.equal(
data.assertions[2].method,
'isDefined',
'A string is not undefined'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,50 +1,69 @@
---
id: 587d824d367417b2b2512c51
title: 测试数组是否包含项目
challengeType: 2
forumTopicId: 301603
title: 测试数组是否包含项目
---
## 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> 上克隆。
</section>
# --description--
## Instructions
<section id='instructions'>
使用 <code>assert.include()</code><code>assert.notInclude()</code> 让所有测试通过。
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=11').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—include 或 notInclude
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=11').then(data => { assert.equal(data.assertions[0].method, 'notInclude', 'It\'s summer in july...'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—include 或 notInclude
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=11').then(data => { assert.equal(data.assertions[1].method, 'include', 'JavaScript is a backend language !!'); }, xhr => { throw new Error(xhr.responseText); })
使用 `assert.include()``assert.notInclude()` 让所有测试通过。
```
# --hints--
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=11').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—include 或 notInclude
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=11').then(
(data) => {
assert.equal(
data.assertions[0].method,
'notInclude',
"It's summer in july..."
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—include 或 notInclude
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=11').then(
(data) => {
assert.equal(
data.assertions[1].method,
'include',
'JavaScript is a backend language !!'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,54 +1,85 @@
---
id: 587d824e367417b2b2512c55
title: 测试对象是否具有某个属性
challengeType: 2
forumTopicId: 301604
title: 测试对象是否具有某个属性
---
## 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>property</code> 断言一个对象含有给定属性。
# --description--
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
## Instructions
<section id='instructions'>
使用 <code>assert.property()</code> 或者 <code>assert.notProperty()</code> 让所有测试通过。
</section>
`property` 断言一个对象含有给定属性。
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=15').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—property 或 notProperty
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=15').then(data => { assert.equal(data.assertions[0].method, 'notProperty', 'A car has not wings'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—property 或 notProperty
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=15').then(data => { assert.equal(data.assertions[1].method, 'property', 'planes have engines'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—property 或 notProperty
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=15').then(data => { assert.equal(data.assertions[2].method, 'property', 'Cars have wheels'); }, xhr => { throw new Error(xhr.responseText); })
使用 `assert.property()` 或者 `assert.notProperty()` 让所有测试通过。
```
# --hints--
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=15').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—property 或 notProperty
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=15').then(
(data) => {
assert.equal(
data.assertions[0].method,
'notProperty',
'A car has not wings'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—property 或 notProperty
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=15').then(
(data) => {
assert.equal(
data.assertions[1].method,
'property',
'planes have engines'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—property 或 notProperty
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=15').then(
(data) => {
assert.equal(data.assertions[2].method, 'property', 'Cars have wheels');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,56 +1,107 @@
---
id: 587d824e367417b2b2512c57
title: 测试对象是否是构造函数的实例
challengeType: 2
forumTopicId: 301605
title: 测试对象是否是构造函数的实例
---
## 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>#instanceOf</code> 断言一个对象是一个构造器的实例。
# --description--
</section>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
## Instructions
<section id='instructions'>
使用 <code>assert.instanceOf()</code><code>assert.notInstanceOf()</code> 让测试通过。
</section>
`#instanceOf` 断言一个对象是一个构造器的实例。
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=17').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—instanceOf 或 notInstanceOf
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=17').then(data => { assert.equal(data.assertions[0].method, 'notInstanceOf', 'myCar is not an instance of Plane'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—instanceOf 或 notInstanceOf
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=17').then(data => { assert.equal(data.assertions[1].method, 'instanceOf', 'airlinePlane is an instance of Plane'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—instanceOf 或 notInstanceOf
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=17').then(data => { assert.equal(data.assertions[2].method, 'instanceOf', 'everything is an Object in JavaScript...'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—instanceOf 或 notInstanceOf
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=17').then(data => { assert.equal(data.assertions[3].method, 'notInstanceOf', 'myCar.wheels is not an instance of String'); }, xhr => { throw new Error(xhr.responseText); })
使用 `assert.instanceOf()``assert.notInstanceOf()` 让测试通过。
```
# --hints--
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=17').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—instanceOf 或 notInstanceOf
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=17').then(
(data) => {
assert.equal(
data.assertions[0].method,
'notInstanceOf',
'myCar is not an instance of Plane'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—instanceOf 或 notInstanceOf
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=17').then(
(data) => {
assert.equal(
data.assertions[1].method,
'instanceOf',
'airlinePlane is an instance of Plane'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—instanceOf 或 notInstanceOf
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=17').then(
(data) => {
assert.equal(
data.assertions[2].method,
'instanceOf',
'everything is an Object in JavaScript...'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—instanceOf 或 notInstanceOf
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=17').then(
(data) => {
assert.equal(
data.assertions[3].method,
'notInstanceOf',
'myCar.wheels is not an instance of String'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,56 +1,103 @@
---
id: 587d824c367417b2b2512c4e
title: 测试一个值是否小于或等于另一个值
challengeType: 2
forumTopicId: 301606
title: 测试一个值是否小于或等于另一个值
---
## 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> 上克隆。
</section>
# --description--
## Instructions
<section id='instructions'>
Use <code>assert.isBelow()</code> (i.e. less than) or <code>assert.isAtLeast()</code> (i.e. greater than or equal) to make the tests pass.
使用 <code>assert.isBelow()</code>(小于)或 <code>assert.isAtLeast()</code>(大于等于)让所有测试通过。
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
</section>
# --instructions--
## Tests
<section id='tests'>
Use `assert.isBelow()` (i.e. less than) or `assert.isAtLeast()` (i.e. greater than or equal) to make the tests pass.
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=8').then(data => {assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isBelow 或 isAtLeast
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=8').then(data => { assert.equal(data.assertions[0].method, 'isAtLeast', '5 is at least (>=) 5'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isBelow 或 isAtLeast
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=8').then(data => { assert.equal(data.assertions[1].method, 'isAtLeast', '2 * Math.random() is at least 0'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isBelow 或 isAtLeast
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=8').then(data => { assert.equal(data.assertions[2].method, 'isBelow', '1 is smaller than 2'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—isBelow 或 isAtLeast
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=8').then(data => { assert.equal(data.assertions[3].method, 'isBelow', '2/3 (0.6666) is smaller than 1'); }, xhr => { throw new Error(xhr.responseText); })
使用 `assert.isBelow()`(小于)或 `assert.isAtLeast()`(大于等于)让所有测试通过。
```
# --hints--
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=8').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—isBelow 或 isAtLeast
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=8').then(
(data) => {
assert.equal(
data.assertions[0].method,
'isAtLeast',
'5 is at least (>=) 5'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—isBelow 或 isAtLeast
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=8').then(
(data) => {
assert.equal(
data.assertions[1].method,
'isAtLeast',
'2 * Math.random() is at least 0'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—isBelow 或 isAtLeast
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=8').then(
(data) => {
assert.equal(data.assertions[2].method, 'isBelow', '1 is smaller than 2');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—isBelow 或 isAtLeast
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=8').then(
(data) => {
assert.equal(
data.assertions[3].method,
'isBelow',
'2/3 (0.6666) is smaller than 1'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,56 +1,77 @@
---
id: 587d824b367417b2b2512c48
title: 使用 Assert.isOk() 和 Assert.isNotOK()
challengeType: 2
forumTopicId: 301607
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> 上克隆。
# --description--
<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>
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆
## Instructions
<section id='instructions'>
`isOk()` 用来测试值是否为 `truthy``isNotOk()` 用来测试值是否为 `falsy`。 如果你想了解更多关于 truthy 和 falsy 值的内容,请参阅 [Falsy Bouncer](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/falsy-bouncer) 这道挑战题目。
使用 <code>assert.isOk()</code><code>assert.isNotOk()</code> 让测试通过。
</section>
# --instructions--
## Tests
<section id='tests'>
使用 `assert.isOk()``assert.isNotOk()` 让测试通过。
```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); })
# --hints--
```
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=2').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—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);
}
);
```
请选择正确的断言—isOk 或 isNotOk
```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);
}
);
```
请选择正确的断言—isOk 或 isNotOk
```js
(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);
}
);
```
# --solutions--

View File

@@ -1,52 +1,71 @@
---
id: 587d824d367417b2b2512c54
title: 使用正则表达式测试字符串
challengeType: 2
forumTopicId: 301608
title: 使用正则表达式测试字符串
---
## 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>match()</code> 断言一个值匹配一个正则表达式(第二个参数)。
</section>
# --description--
## Instructions
<section id='instructions'>
使用 <code>assert.match()</code> 让所有测试通过。
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
</section>
`match()` 断言一个值匹配一个正则表达式(第二个参数)。
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=14').then(data => { assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—match 或 notMatch
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/get-tests?type=unit&n=14'').then(data => { assert.equal(data.assertions[0].method, ''match'', ''\''# name: John Doe, age: 35\'' matches the regex''); }, xhr => { throw new Error(xhr.responseText); })'
- text: 请选择正确的断言—match 或 notMatch
testString: 'getUserInput => $.get(getUserInput(''url'') + ''/_api/get-tests?type=unit&n=14'').then(data => { assert.equal(data.assertions[1].method, ''notMatch'', ''\''# name: Paul Smith III, age: twenty-four\'' does not match the regex (the age must be numeric)''); }, xhr => { throw new Error(xhr.responseText); })'
使用 `assert.match()` 让所有测试通过。
```
# --hints--
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=14').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—match 或 notMatch
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=14').then(
(data) => {
assert.equal(
data.assertions[0].method,
'match',
"'# name: John Doe, age: 35' matches the regex"
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—match 或 notMatch
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=14').then(
(data) => {
assert.equal(
data.assertions[1].method,
'notMatch',
"'# name: Paul Smith III, age: twenty-four' does not match the regex (the age must be numeric)"
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,56 +1,103 @@
---
id: 587d824b367417b2b2512c4a
title: 用两个等号断言相等
challengeType: 2
forumTopicId: 301609
title: 用两个等号断言相等
---
## 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>equal()</code> 使用 <code>==</code> 比较对象。
</section>
# --description--
## Instructions
<section id='instructions'>
使用 <code>assert.equal()</code><code>assert.notEqual()</code> 让所有测试通过。
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
</section>
`equal()` 使用 `==` 比较对象。
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=4').then(data => {assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—equal 或 notEqual
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=4').then(data => { assert.equal(data.assertions[0].method, 'equal', 'Numbers are coerced into strings with == '); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—equal 或 notEqual
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=4').then(data => { assert.equal(data.assertions[1].method, 'notEqual', ' == compares object references'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—equal 或 notEqual
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=4').then(data => { assert.equal(data.assertions[2].method, 'equal', '6 * \'2\' is 12 ! It should be equal to \'12\''); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—equal 或 notEqual
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=4').then(data => { assert.equal(data.assertions[3].method, 'notEqual', '6 + \'2\' is \'62\'...'); }, xhr => { throw new Error(xhr.responseText); })
使用 `assert.equal()``assert.notEqual()` 让所有测试通过。
```
# --hints--
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=4').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—equal 或 notEqual
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=4').then(
(data) => {
assert.equal(
data.assertions[0].method,
'equal',
'Numbers are coerced into strings with == '
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—equal 或 notEqual
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=4').then(
(data) => {
assert.equal(
data.assertions[1].method,
'notEqual',
' == compares object references'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—equal 或 notEqual
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=4').then(
(data) => {
assert.equal(
data.assertions[2].method,
'equal',
"6 * '2' is 12 ! It should be equal to '12'"
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—equal 或 notEqual
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=4').then(
(data) => {
assert.equal(data.assertions[3].method, 'notEqual', "6 + '2' is '62'...");
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--

View File

@@ -1,56 +1,103 @@
---
id: 587d824b367417b2b2512c4b
title: 用三个等号断言严格相等
challengeType: 2
forumTopicId: 301610
title: 用三个等号断言严格相等
---
## 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>strictEqual()</code> 使用 <code>===</code> 比较对象。
</section>
# --description--
## Instructions
<section id='instructions'>
使用 <code>assert.strictEqual()</code><code>assert.notStrictEqual()</code> 让所有测试通过。
请注意,本项目在 [这个 Repl.it 项目](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 的基础上进行开发。你也可以从 [GitHub](https://repl.it/github/freeCodeCamp/boilerplate-mochachai) 上克隆。
</section>
`strictEqual()` 使用 `===` 比较对象。
## Tests
<section id='tests'>
# --instructions--
```yml
tests:
- text: 不应有未通过的测试
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=5').then(data => {assert.equal(data.state,'passed'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—strictEqual 或 notStrictEqual
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=5').then(data => { assert.equal(data.assertions[0].method, 'notStrictEqual', 'with strictEqual the type must match'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—strictEqual 或 notStrictEqual
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=5').then(data => { assert.equal(data.assertions[1].method, 'strictEqual', '3*2 = 6...'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—strictEqual 或 notStrictEqual
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=5').then(data => { assert.equal(data.assertions[2].method, 'strictEqual', '6 * \'2\' is 12. Types match !'); }, xhr => { throw new Error(xhr.responseText); })
- text: 请选择正确的断言—strictEqual 或 notStrictEqual
testString: getUserInput => $.get(getUserInput('url') + '/_api/get-tests?type=unit&n=5').then(data => { assert.equal(data.assertions[3].method, 'notStrictEqual', 'Even if they have the same elements, the Arrays are notStrictEqual'); }, xhr => { throw new Error(xhr.responseText); })
使用 `assert.strictEqual()``assert.notStrictEqual()` 让所有测试通过。
```
# --hints--
</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.
*/
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=5').then(
(data) => {
assert.equal(data.state, 'passed');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
</section>
请选择正确的断言—strictEqual 或 notStrictEqual
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=5').then(
(data) => {
assert.equal(
data.assertions[0].method,
'notStrictEqual',
'with strictEqual the type must match'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—strictEqual 或 notStrictEqual
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=5').then(
(data) => {
assert.equal(data.assertions[1].method, 'strictEqual', '3*2 = 6...');
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—strictEqual 或 notStrictEqual
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=5').then(
(data) => {
assert.equal(
data.assertions[2].method,
'strictEqual',
"6 * '2' is 12. Types match !"
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
请选择正确的断言—strictEqual 或 notStrictEqual
```js
(getUserInput) =>
$.get(getUserInput('url') + '/_api/get-tests?type=unit&n=5').then(
(data) => {
assert.equal(
data.assertions[3].method,
'notStrictEqual',
'Even if they have the same elements, the Arrays are notStrictEqual'
);
},
(xhr) => {
throw new Error(xhr.responseText);
}
);
```
# --solutions--