storybook-addon-specifications
Advanced tools
Comparing version 1.0.12 to 1.0.13
@@ -1,3 +0,1 @@ | ||
import {mount} from "enzyme"; | ||
export const storiesOf = function storiesOf() { | ||
@@ -23,3 +21,3 @@ var api = {}; | ||
export const specs = (spec) => { | ||
spec(); | ||
spec() | ||
}; | ||
@@ -29,3 +27,4 @@ | ||
it(name, function () { | ||
const tree = mount(story).html(); | ||
let renderer = require("react-test-renderer"); | ||
const tree = renderer.create(story).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
@@ -32,0 +31,0 @@ }); |
{ | ||
"name": "storybook-addon-specifications", | ||
"version": "1.0.12", | ||
"version": "1.0.13", | ||
"description": "Add tests to your react storybook stories", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -151,9 +151,9 @@ # Specifications Addon [![npm version](https://img.shields.io/npm/v/storybook-addon-specifications.svg)](https://www.npmjs.com/package/storybook-addon-specifications) | ||
>**Warning :** This part will describe how to add automatically jest snapshot to every story you write. It will allow you to take advantage of this jest feature but will not have any effect inside storybook. Indeed, you don't even need to add this addon to your project if you don't plan to use the specs() function. If I describe the idea here, it's only because it uses the trick I explain before allowing you to write tests inside stories and still be able to execute them with a test runner. | ||
>**Warning :** This part will describe how to add automatically jest snapshot to every story you write. It will allow you to take advantage of this jest feature but will not have any effect inside storybook. Indeed, you don't even need to add this addon to your project if you don't plan to use the specs() function. If I describe the idea here, it's only because it uses the trick I explained before allowing you to write tests inside stories and still be able to execute them with a test runner. | ||
If you want to use jest snapshot testing with every story you write, that's totally possible. All you need to do is modify a bit the facade.js mock file to look like this : | ||
![](docs/snapshot-jest.png) | ||
The only thing to do is to modify the facade.js mock file (the one used by jest) to look like this : | ||
```js | ||
import {mount} from "enzyme"; | ||
export const storiesOf = function storiesOf() { | ||
@@ -179,12 +179,11 @@ var api = {}; | ||
export const specs = (spec) => { | ||
spec(); | ||
spec() | ||
}; | ||
export const snapshot = (name, story) => { | ||
describe(name + ' snapshot', function () { | ||
it(name, function () { | ||
const tree = mount(story).html(); | ||
let renderer = require("react-test-renderer"); | ||
const tree = renderer.create(story).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); | ||
}; | ||
@@ -196,8 +195,6 @@ | ||
For every story added to storybook, it will make a snapshot. | ||
Every story added to storybook, will now have a snapshot. | ||
Here, I use enzyme to render the component under testing. I do that because it appears that if you use enzyme for others tests, it doesn't mix well with react-test-renderer. But if you do not use enzyme for your tests, then you should be good to go with react-test-renderer rendering. | ||
If for any reason you want to choose stories that will be snapshoted, that's also possible. | ||
1. remove snapshot() function calls from add and addWithInfo in facade.js mock file. | ||
If for any reason you want to choose when to snapshot a story, that's also possible. | ||
1. remove snapshot() function calls from add and addWithInfo in facade.js mock file. | ||
2. use the snapshot() function directly inside the story like you do with specs() | ||
@@ -204,0 +201,0 @@ 3. Add this line to the facade.js file used for import functions. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
733615
33
626
251