-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a
snapshotWithOptions
test body and example
See for instance #896 -- it's a common problem to need mocked nodes. This solution is probably a bit of a bandaid, as large projects would probably want to set options per-story, this is a lot better than nothing in the meantime.
- Loading branch information
Showing
6 changed files
with
35 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React, { Component } from 'react'; | ||
|
||
class ComponentWithRef extends Component { | ||
componentDidMount() { | ||
// Read the scroll width off the DOM element | ||
console.log(this.ref.scrollWidth); | ||
} | ||
render() { | ||
return <div ref={r => (this.ref = r)} />; | ||
} | ||
} | ||
|
||
export default ComponentWithRef; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import initStoryshots from '@storybook/addon-storyshots'; | ||
import initStoryshots, { snapshotWithOptions } from '@storybook/addon-storyshots'; | ||
import path from 'path'; | ||
|
||
function createNodeMock(element) { | ||
if (element.type === 'div') { | ||
return { scrollWidth: 123 }; | ||
} | ||
return null; | ||
} | ||
|
||
initStoryshots({ | ||
framework: 'react', | ||
configPath: path.join(__dirname, '..', '.storybook'), | ||
test: snapshotWithOptions({ | ||
createNodeMock, | ||
}), | ||
}); |