Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-25 09:06:19 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-25 09:06:19 +0300
commit8f8838a1d9d045fd75cfa70c4f7daa4f080084e9 (patch)
tree5452c715417625620afb7474ab036d5bf24f04ae /doc/development/testing_guide/frontend_testing.md
parent543081566d10160511ef09e929195ef3f48f5fa3 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/development/testing_guide/frontend_testing.md')
-rw-r--r--doc/development/testing_guide/frontend_testing.md44
1 files changed, 44 insertions, 0 deletions
diff --git a/doc/development/testing_guide/frontend_testing.md b/doc/development/testing_guide/frontend_testing.md
index 314995ca9b3..d0669c5ebd4 100644
--- a/doc/development/testing_guide/frontend_testing.md
+++ b/doc/development/testing_guide/frontend_testing.md
@@ -119,6 +119,50 @@ Global mocks introduce magic and can affect how modules are imported in your tes
When in doubt, construct mocks in your test file using [`jest.mock()`](https://jestjs.io/docs/en/jest-object#jestmockmodulename-factory-options), [`jest.spyOn()`](https://jestjs.io/docs/en/jest-object#jestspyonobject-methodname), etc.
+### Data-driven tests
+
+Similar to [RSpec's parameterized tests](best_practices.md#table-based--parameterized-tests),
+Jest supports data-driven tests for:
+
+- Individual tests using [`test.each`](https://jestjs.io/docs/en/api#testeachtable-name-fn-timeout) (aliased to `it.each`).
+- Groups of tests using [`describe.each`](https://jestjs.io/docs/en/api#describeeachtable-name-fn-timeout).
+
+These can be useful for reducing repetition within tests. Each option can take an array of
+data values or a tagged template literal.
+
+For example:
+
+```javascript
+// function to test
+const icon = status => status ? 'pipeline-passed' : 'pipeline-failed'
+const message = status => status ? 'pipeline-passed' : 'pipeline-failed'
+
+// test with array block
+it.each([
+ [false, 'pipeline-failed'],
+ [true, 'pipeline-passed']
+])('icon with %s will return %s',
+ (status, icon) => {
+ expect(renderPipeline(status)).toEqual(icon)
+ }
+);
+
+// test suite with tagged template literal block
+describe.each`
+ status | icon | message
+ ${false} | ${'pipeline-failed'} | ${'Pipeline failed - boo-urns'}
+ ${true} | ${'pipeline-passed'} | ${'Pipeline succeeded - win!'}
+`('pipeline component', ({ status, icon, message }) => {
+ it(`returns icon ${icon} with status ${status}`, () => {
+ expect(icon(status)).toEqual(message)
+ })
+
+ it(`returns message ${message} with status ${status}`, () => {
+ expect(message(status)).toEqual(message)
+ })
+});
+```
+
## Karma test suite
GitLab uses the [Karma][karma] test runner with [Jasmine] as its test