forked from jest-community/snapshot-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow custom serializers through setSerializers
Provides new setSerializers function to set the serializer objects to be used before diffing. React component serializer implementation using `react-test-renderer` has been extracted out. Fixes jest-community#18 Fixes jest-community#30 Fixes jest-community#31
- Loading branch information
1 parent
8cc8f70
commit 6afc4a0
Showing
8 changed files
with
859 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`default rendered components can use contextLines 1`] = ` | ||
"Snapshot Diff: | ||
- <NestedComponent test=\\"say\\" /> | ||
+ <NestedComponent test=\\"my name\\" /> | ||
@@ -4,1 +4,1 @@ | ||
- say | ||
+ my name" | ||
`; | ||
|
||
exports[`default rendered components diffs components 1`] = ` | ||
"Snapshot Diff: | ||
- <NestedComponent test=\\"say\\" /> | ||
+ <NestedComponent test=\\"my name\\" /> | ||
@@ -1,9 +1,9 @@ | ||
<div> | ||
<span> | ||
Hello World - | ||
- say | ||
+ my name | ||
</span> | ||
<div> | ||
I have value | ||
1234 | ||
</div>" | ||
`; | ||
exports[`enzyme shallow rendered components can use contextLines 1`] = ` | ||
"Snapshot Diff: | ||
- First value | ||
+ Second value | ||
@@ -4,1 +4,1 @@ | ||
- say | ||
+ my name" | ||
`; | ||
exports[`enzyme shallow rendered components diffs components 1`] = ` | ||
"Snapshot Diff: | ||
- First value | ||
+ Second value | ||
<div> | ||
<span> | ||
Hello World - | ||
- say | ||
+ my name | ||
</span> | ||
<Component | ||
value={1234} | ||
/> | ||
</div>" | ||
`; | ||
exports[`react test-renderer shallow rendered components can use contextLines 1`] = ` | ||
"Snapshot Diff: | ||
- <div><span>Hello World - say</span><Component value={1234} /></div> | ||
+ <div><span>Hello World - my name</span><Component value={1234} /></div> | ||
@@ -4,1 +4,1 @@ | ||
- say | ||
+ my name" | ||
`; | ||
exports[`react test-renderer shallow rendered components diffs components 1`] = ` | ||
"Snapshot Diff: | ||
- <div><span>Hello World - say</span><Component value={1234} /></div> | ||
+ <div><span>Hello World - my name</span><Component value={1234} /></div> | ||
@@ -1,9 +1,9 @@ | ||
<div> | ||
<span> | ||
Hello World - | ||
- say | ||
+ my name | ||
</span> | ||
<div> | ||
I have value | ||
1234 | ||
</div>" | ||
`; | ||
exports[`values which are not components can use contextLines 1`] = ` | ||
"Snapshot Diff: | ||
- First value | ||
+ Second value | ||
@@ -3,1 +3,1 @@ | ||
- \\"hello\\": \\"world\\", | ||
+ \\"hello\\": \\"there\\"," | ||
`; | ||
exports[`values which are not components diffs objects 1`] = ` | ||
"Snapshot Diff: | ||
- First value | ||
+ Second value | ||
Object { | ||
\\"foo\\": \\"bar\\", | ||
- \\"hello\\": \\"world\\", | ||
+ \\"hello\\": \\"there\\", | ||
\\"testing\\": 123, | ||
}" | ||
`; |
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,117 @@ | ||
// @flow | ||
const React = require('react'); | ||
const { configure, shallow: enzymeShallow } = require('enzyme'); | ||
const ReactShallowRenderer = require('react-test-renderer/shallow'); | ||
const Adapter = require('enzyme-adapter-react-16'); | ||
const enzymeToJson = require('enzyme-to-json/serializer'); | ||
const snapshotDiff = require('../src/index'); | ||
|
||
configure({ adapter: new Adapter() }); | ||
const reactShallow = new ReactShallowRenderer(); | ||
|
||
snapshotDiff.setSerializers([...snapshotDiff.defaultSerializers, enzymeToJson]); | ||
|
||
type Props = { | ||
test: string, | ||
}; | ||
|
||
const Component = ({ value }) => <div>I have value {value}</div>; | ||
|
||
const NestedComponent = (props: Props) => ( | ||
<div> | ||
<span>Hello World - {props.test}</span> | ||
<Component value={1234} /> | ||
</div> | ||
); | ||
|
||
describe('default rendered components', () => { | ||
test('diffs components', () => { | ||
expect( | ||
snapshotDiff( | ||
<NestedComponent test="say" />, | ||
<NestedComponent test="my name" /> | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
test('can use contextLines', () => { | ||
expect( | ||
snapshotDiff( | ||
<NestedComponent test="say" />, | ||
<NestedComponent test="my name" />, | ||
{ | ||
contextLines: 0, | ||
} | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('enzyme shallow rendered components', () => { | ||
test('diffs components', () => { | ||
expect( | ||
snapshotDiff( | ||
enzymeShallow(<NestedComponent test="say" />), | ||
enzymeShallow(<NestedComponent test="my name" />) | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
test('can use contextLines', () => { | ||
expect( | ||
snapshotDiff( | ||
enzymeShallow(<NestedComponent test="say" />), | ||
enzymeShallow(<NestedComponent test="my name" />), | ||
{ | ||
contextLines: 0, | ||
} | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('react test-renderer shallow rendered components', () => { | ||
test('diffs components', () => { | ||
expect( | ||
snapshotDiff( | ||
reactShallow.render(<NestedComponent test="say" />), | ||
reactShallow.render(<NestedComponent test="my name" />) | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
test('can use contextLines', () => { | ||
expect( | ||
snapshotDiff( | ||
reactShallow.render(<NestedComponent test="say" />), | ||
reactShallow.render(<NestedComponent test="my name" />), | ||
{ | ||
contextLines: 0, | ||
} | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('values which are not components', () => { | ||
test('diffs objects', () => { | ||
expect( | ||
snapshotDiff( | ||
{ foo: 'bar', hello: 'world', testing: 123 }, | ||
{ foo: 'bar', hello: 'there', testing: 123 } | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
test('can use contextLines', () => { | ||
expect( | ||
snapshotDiff( | ||
{ foo: 'bar', hello: 'world', testing: 123 }, | ||
{ foo: 'bar', hello: 'there', testing: 123 }, | ||
{ | ||
contextLines: 0, | ||
} | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
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,3 +1,4 @@ | ||
/* global expect */ | ||
const { toMatchDiffSnapshot } = require('./build/'); | ||
|
||
expect.extend({ toMatchDiffSnapshot }); | ||
expect.extend({ toMatchDiffSnapshot }); |
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
Oops, something went wrong.