Frotnend-разработчик в Kaliber5
https://lolma.us
https://github.com/lolmaus
https://kaliber5.de
assert.isEqual(actual, expected)expect(actual).to.equal(expected)actual.should.equal(expected)TDD
Пишем
падающий
юнит-тест
Пишем
код
Unit-тест
проходит
Рефакторим
Пишем падающий сценарий
Рефакторим
Сценарий проходит
Feature: The blog.
Scenario: Visiting the blog with posts
Given there are 3 posts in the database
When I visit the blog page
Then I should see 3 posts
And I should not see the empty blog message
Scenario: Visiting an empty blog
Given there are 0 blog posts in the database
When I visit the blog page
Then I should see 0 posts
And I should see the empty blog messageПреимущества Cucumber
Проблемы Cucumber
Проблемы Cucumber
Scenario: Viewing blog posts
Given there are 3 posts in the database
When I visit the blog
Then the title of the 1st post should be "Hello World"Проблемы Cucumber
When I expand the 2nd post
Then the expanded post should be expandedПроблемы Cucumber
When I click on div p ul li:nth-child(2) aПроблемы Cucumber
Решения
Решения
Решения
Было:
Then the 1st product should be selectedСтало:
Then ".product:nth-child(1)" should have HTML class "is-selected"
And I should see ".product:nth-child(1) .comments"Было:
Given there are 2 posts in the database
# ...
Then the title of the 1st post should be "Hello world!"Стало:
Given there are records of type "Post" in the database:
---------------------------------------------------
| id | title | body | authorId |
| "1" | "Hello world!" | "Lorem ipsum" | "1" |
| "2" | "Foo Bar" | "Lorem ipsum" | "1" |
---------------------------------------------------
# ...
Then the title of the 1st post should be "Hello world"Решения
Было:
When I click on div p ul li:nth-child(2) aСтало:
When I click on "[data-test-post]:nth-child(2) [data-test-title]"4. Используем только семантические селекторы
[data-test-main-menu] data-test-main-menu main-menu Main-Menu4. Используем только семантические селекторы с удобным, но намеренно ограниченным синтаксисом
When I click [data-test-post]:nth-child(2) [data-test-expand-button]4. Используем только семантические селекторы с удобным, но намеренно ограниченным синтаксисом
When I click the Expand-Button in the 2nd PostБыло:
Стало:
<div class="container">
<article data-test-post>
</article>
</div>
<div class="container">
<article data-test-post>
</article>
<article data-test-post>
</article>
</div>
<div class="container">
<article data-test-post>
</article>
<article data-test-post>
</article>
</div>Проблема :nth-child()
2nd Post
[data-test-post]
:nth-child(2)
<div class="container">
<article data-test-post>
</article>
</div>
<div class="container">
<article data-test-post>
</article>
<article data-test-post>
</article>
</div>
<div class="container">
<article data-test-post>
</article>
<article data-test-post>
</article>
</div>Решение: селектор :eq(2) из jQuery
2nd Post
[data-test-post]
:eq(2)
1
2
3
4
5
Решения
5. Добавляем удобный вывод ошибок
Всем спасибо! ^_^
http://bit.ly/cucumber-ember-nn-2021
Секретный слайд