Skip to content

Commit

Permalink
Merge pull request #2398 from storybooks/bugfix/addon-jest-fix-wrong-…
Browse files Browse the repository at this point in the history
…examples

Fix wrong "withTests" examples + add documentation
  • Loading branch information
Hypnosphi authored Nov 29, 2017
2 parents 1995b60 + cea3f08 commit bb86e68
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions addons/jest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => (
<div>Jest results in storybook</div>
));
Expand All @@ -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,
});
```

Expand All @@ -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
Expand Down

0 comments on commit bb86e68

Please sign in to comment.