From 28e8ed569c0bb30760d765a39efb1cd7dcb050aa Mon Sep 17 00:00:00 2001 From: Renaud TERTRAIS Date: Wed, 29 Nov 2017 16:54:11 +0100 Subject: [PATCH] Fix wrong "withTests" examples + add documentation --- addons/jest/README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/addons/jest/README.md b/addons/jest/README.md index 5ccc32d1829c..40555e3ade01 100644 --- a/addons/jest/README.md +++ b/addons/jest/README.md @@ -77,11 +77,11 @@ Assuming that you have created a test files `MyComponent.test.js` and `MyOtherCo In your `story.js` ```js -import jestTestResults from '../.jest-test-results.json'; +import results from '../.jest-test-results.json'; import { withTests } from '@storybook/addon-jest'; storiesOf('MyComponent', module) - .addDecorator(withTests(jestTestResults, { filesExt: '.test.js' })('MyComponent', 'MyOtherComponent')) + .addDecorator(withTests({ results })('MyComponent', 'MyOtherComponent')) .add('This story shows test results from MyComponent.test.js and MyOtherComponent.test.js', () => (
Jest results in storybook
)); @@ -90,11 +90,11 @@ storiesOf('MyComponent', module) Or in order to avoid importing `.jest-test-results.json` in each story, you can create a simple file `withTests.js`: ```js -import jestTestResults from '../.jest-test-results.json'; +import results from '../.jest-test-results.json'; import { withTests } from '@storybook/addon-jest'; -export default withTests(jestTestResults, { - filesExt: '.test.js', +export default withTests({ + results, }); ``` @@ -111,6 +111,11 @@ storiesOf('MyComponent', module) )); ``` +### withTests(options) + +- **options.results**: [OBJECT] jest output results. *mandatory* +- **filteExt**: [STRING] test file extention. *optionnal*. This allow you to write "MyComponent" and not "MyComponent.test.js". It will be used as regex to find your file results. Default value is `((\\.specs?)|(\\.tests?))?(\\.js)?$`. That mean it will match: MyComponent.js, MyComponent.test.js, MyComponent.tests.js, MyComponent.spec.js, MyComponent.specs.js... + ## TODO - [ ] Add coverage