Открыть боковую панель
nt_test121
nt_project_9da4a5yt9x4b
Коммиты
4950dd97
Коммит
4950dd97
создал
Май 11, 2017
по автору
winh
Просмотр файлов
Document Promise testing best practice (!11284)
владелец
fb31c6ce
Изменения
1
Скрыть пробелы
Построчно
Рядом
doc/development/fe_guide/testing.md
Просмотр файла @
4950dd97
...
...
@@ -68,6 +68,68 @@ describe('.methodName', () => {
});
});
```
#### Testing Promises
When testing Promises you should always make sure that the test is asynchronous and rejections are handled.
Your Promise chain should therefore end with a call of the
`done`
callback and
`done.fail`
in case an error occurred.
```
javascript
/// Good
it
(
'
tests a promise
'
,
(
done
)
=>
{
promise
.
then
((
data
)
=>
{
expect
(
data
).
toBe
(
asExpected
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
/// Good
it
(
'
tests a promise rejection
'
,
(
done
)
=>
{
promise
.
catch
((
error
)
=>
{
expect
(
error
).
toBe
(
expectedError
);
})
.
then
(
done
)
.
catch
(
done
.
fail
);
});
/// Bad (missing done callback)
it
(
'
tests a promise
'
,
()
=>
{
promise
.
then
((
data
)
=>
{
expect
(
data
).
toBe
(
asExpected
);
})
});
/// Bad (missing catch)
it
(
'
tests a promise
'
,
(
done
)
=>
{
promise
.
then
((
data
)
=>
{
expect
(
data
).
toBe
(
asExpected
);
})
.
then
(
done
)
});
/// Bad (use done.fail in asynchronous tests)
it
(
'
tests a promise
'
,
(
done
)
=>
{
promise
.
then
((
data
)
=>
{
expect
(
data
).
toBe
(
asExpected
);
})
.
then
(
done
)
.
catch
(
fail
)
});
/// Bad (missing catch)
it
(
'
tests a promise rejection
'
,
(
done
)
=>
{
promise
.
catch
((
error
)
=>
{
expect
(
error
).
toBe
(
expectedError
);
})
.
then
(
done
)
});
```
#### Stubbing
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать