Files
freeCodeCamp/guide/russian/miscellaneous/testing-with-chaijs/index.md
2018-10-16 21:32:40 +05:30

41 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Testing with Chaijs
localeTitle: Тестирование с помощью Chaijs
---
[Chai](http://chaijs.com) - это тестовая библиотека для Node.js.
### Монтаж
Вы можете установить Chai в свой проект через npm.
```
npm install chai
```
##### Pro-наконечник
Добавьте Chai в devDependencies _package.json_ , используя \* как тег версии. Таким образом, вы всегда имеете самую последнюю версию.
```
"devDependencies": {
"chai": "*"
}
```
### Как пользоваться
#### утверждать
Вы можете использовать _assert_ для проверки эффективности тестов.
```
var assert = require('chai').assert, foo = 'bar', beverages = { tea: [ 'chai', 'matcha', 'oolong' ] };
assert.typeOf(foo, 'string'); // without optional message
assert.typeOf(foo, 'string', 'foo is a string'); // with optional message
assert.equal(foo, 'bar', 'foo equal `bar`');
assert.lengthOf(foo, 3, 'foo`s value has a length of 3');
assert.lengthOf(beverages.tea, 3, 'beverages has 3 types of tea');
```
### Больше информации:
* `help chai assert`
* `help chai expectations`