-
Notifications
You must be signed in to change notification settings - Fork 22
spec__utils #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
spec__utils #90
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| Утилиты для написания тестов | ||
| ============================ | ||
|
|
||
| Проект `bem-pr` содержит набор утилит для упрощенного написания тестов клиентского кода BEM-блоков, эти утилиты доступны в модуле `spec__utils`. | ||
| Пример теста, использующего утилиты: | ||
|
|
||
| ```js | ||
| modules.define('spec', ['spec__utils'], function(provide, utils) { | ||
|
|
||
| describe('test-block', function() { | ||
|
|
||
| var bemjson = { | ||
| block : 'test-block', | ||
| mods : { someMod : 'someVal' } | ||
| }; | ||
|
|
||
| it('should init successfully', function() { | ||
| var block = utils.buildBlock('test-block', bemjson); | ||
|
|
||
| block.getMod('someMod').should.equal('someVal'); | ||
|
|
||
| utils.destruct(block); // Настоятельно рекомендуем очищать блок после теста | ||
| }); | ||
|
|
||
| }); | ||
| }); | ||
| ``` | ||
|
|
||
| ## Доступные функции | ||
|
|
||
| ### buildBlock(name, bemjson) | ||
|
|
||
| Инициализирует и возвращает BEM-блок `name` на основе переданного `bemjson`. | ||
|
|
||
| ### destruct(block) | ||
|
|
||
| Удаляет блок и DOM-дерева. Рекомендуется вызывать эту функцию после каждого теста для всех созданных блоков. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| [{ | ||
| mustDeps: [ | ||
| { block : 'i-bem', elem : 'dom' }, | ||
| { block : 'BEMHTML' }, | ||
| { block : 'jquery' } | ||
| ] | ||
| }] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /** | ||
| * @module spec__utils | ||
| */ | ||
| modules.define('spec__utils', ['i-bem__dom', 'BEMHTML', 'jquery'], function(provide, BEMDOM, BEMHTML, $) { | ||
|
|
||
| provide({ | ||
| /** | ||
| * Builds a block by name and bemjson | ||
| * | ||
| * @function buildBlock | ||
| * @param {string} name | ||
| * @param {object} bemjson | ||
| * @return {object} bem block | ||
| */ | ||
| buildBlock : function(name, bemjson) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. я бы добавил еще опциональный 3-й аргумент |
||
| bemjson = bemjson || { block : name }; | ||
| return BEMDOM.init($(BEMHTML.apply(bemjson)).appendTo('body')).bem(name); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Почему не |
||
| }, | ||
|
|
||
| /** | ||
| * Clean up block | ||
| * | ||
| * @function destruct | ||
| * @param {object} block bem block | ||
| */ | ||
| destruct : function(block) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Наверное,
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Изначально было сделано по аналогии с
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ok |
||
| BEMDOM.destruct(block.domElem); | ||
| } | ||
| }); | ||
|
|
||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| 'sinon', | ||
| 'sinon-chai', | ||
| 'simulate-dom-event', | ||
| 'jquery' | ||
| 'jquery', | ||
| { elem : 'utils' } | ||
| ] | ||
| }] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Давай это унесем в какой-нибудь
i-bem__dom-specsили хотя быspec__i-bem-dom. Для элемента абстрактногоspec, который про i-bem вообще ничего знать не должен, тут слишком много i-bem'а :)