freeCodeCamp/guide/russian/miscellaneous/testing-with-chaijs/index.md

41 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
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`