-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1090 from storybooks/component-with-ref-example
Added `snapshotWithOptions` to allow configuring rendering options in Storyshots
- Loading branch information
Showing
7 changed files
with
40 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
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, | ||
}), | ||
}); |