-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fixed serializer and added proper tests (#33)
* Fixed serializer and added proper tests * Dependencies upgrade
- Loading branch information
1 parent
226c01c
commit 309d6ea
Showing
33 changed files
with
3,154 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
node_modules | ||
coverage | ||
build | ||
jsconfig.json | ||
/serializer.js | ||
.vscode |
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 |
---|---|---|
@@ -1,13 +1,11 @@ | ||
import ShallowWrapper from 'enzyme/build/ShallowWrapper'; | ||
import ReactWrapper from 'enzyme/build/ReactWrapper'; | ||
|
||
import {isEnzymeWrapper} from './build/utils'; | ||
import toJson from './'; | ||
|
||
module.exports = { | ||
test(wrapper) { | ||
return wrapper instanceof ShallowWrapper || wrapper instanceof ReactWrapper || wrapper.cheerio; | ||
return isEnzymeWrapper(wrapper); | ||
}, | ||
print(wrapper) { | ||
return toJson(wrapper); | ||
print(wrapper, serializer) { | ||
return serializer(toJson(wrapper)); | ||
}, | ||
}; |
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,11 @@ | ||
import ShallowWrapper from 'enzyme/build/ShallowWrapper'; | ||
import ReactWrapper from 'enzyme/build/ReactWrapper'; | ||
|
||
const SHALLOW_WRAPPER_NAME = ShallowWrapper.name; | ||
const REACT_WRAPPER_NAME = ReactWrapper.name; | ||
|
||
export const isShallowWrapper = wrapper => wrapper && wrapper.constructor && wrapper.constructor.name === SHALLOW_WRAPPER_NAME; | ||
export const isReactWrapper = wrapper => wrapper && wrapper.constructor && wrapper.constructor.name === REACT_WRAPPER_NAME; | ||
export const isCheerioWrapper = wrapper => wrapper.cheerio; | ||
|
||
export const isEnzymeWrapper = wrapper => isShallowWrapper(wrapper) || isReactWrapper(wrapper) || isCheerioWrapper(wrapper); |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
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 @@ | ||
node_modules |
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,22 @@ | ||
{ | ||
"name": "serializer-test", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "jest" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"jest": { | ||
"snapshotSerializers": [ | ||
"<rootDir>/../../serializer" | ||
] | ||
}, | ||
"devDependencies": { | ||
"enzyme": "file:../../node_modules/enzyme", | ||
"jest": "file:../../node_modules/jest", | ||
"react": "file:../../node_modules/react" | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/serializer/tests/__snapshots__/examples.test.js.snap
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,20 @@ | ||
exports[`test renders correctly 1`] = ` | ||
<div | ||
className="my-component" | ||
onClick={[Function]}> | ||
<span | ||
className="count"> | ||
1 | ||
</span> | ||
<strong> | ||
Hello World! | ||
</strong> | ||
</div> | ||
`; | ||
|
||
exports[`test renders span after setState 1`] = ` | ||
<span | ||
className="count"> | ||
42 | ||
</span> | ||
`; |
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,21 @@ | ||
exports[`test renders a \`span\` correctly 1`] = ` | ||
<span> | ||
<span> | ||
Hello World! | ||
</span> | ||
</span> | ||
`; | ||
|
||
exports[`test renders a \`strong\` correctly 1`] = ` | ||
<span> | ||
<strong> | ||
Hello World! | ||
</strong> | ||
</span> | ||
`; | ||
|
||
exports[`test renders the right title 1`] = ` | ||
<h3> | ||
Component Title | ||
</h3> | ||
`; |
148 changes: 148 additions & 0 deletions
148
tests/serializer/tests/__snapshots__/mount.test.js.snap
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,148 @@ | ||
exports[`test converts a class mount with a class component in it as a direct child 1`] = ` | ||
<ClassWithDirectComponent | ||
className="class"> | ||
<ClassWithPure | ||
className="nested-pure"> | ||
<div | ||
className="class-with-pure nested-pure" | ||
onClick={[Function]}> | ||
<BasicPure | ||
className="nested-pure"> | ||
<div | ||
className="basic-pure nested-pure" | ||
onClick={[Function]}> | ||
<div | ||
className="group" | ||
id="group-id"> | ||
<span> | ||
<span> | ||
<span> | ||
<strong> | ||
Hello! | ||
</strong> | ||
</span> | ||
<span | ||
className="empty" /> | ||
</span> | ||
<span | ||
className="empty" /> | ||
</span> | ||
<span | ||
className="empty" /> | ||
</div> | ||
</div> | ||
</BasicPure> | ||
</div> | ||
</ClassWithPure> | ||
</ClassWithDirectComponent> | ||
`; | ||
|
||
exports[`test converts a class mount with a pure function in it 1`] = ` | ||
<ClassWithPure | ||
className="class"> | ||
<div | ||
className="class-with-pure class" | ||
onClick={[Function]}> | ||
<BasicPure | ||
className="nested-pure"> | ||
<div | ||
className="basic-pure nested-pure" | ||
onClick={[Function]}> | ||
<div | ||
className="group" | ||
id="group-id"> | ||
<span> | ||
<span> | ||
<strong> | ||
Hello! | ||
</strong> | ||
</span> | ||
<span | ||
className="empty" /> | ||
</span> | ||
<span | ||
className="empty" /> | ||
</div> | ||
</div> | ||
</BasicPure> | ||
</div> | ||
</ClassWithPure> | ||
`; | ||
|
||
exports[`test converts a class mount with a pure function in it as a direct child 1`] = ` | ||
<ClassWithDirectPure | ||
className="class"> | ||
<BasicPure | ||
className="nested-pure"> | ||
<div | ||
className="basic-pure nested-pure" | ||
onClick={[Function]}> | ||
<div | ||
className="group" | ||
id="group-id"> | ||
<span> | ||
<span> | ||
<strong> | ||
Hello! | ||
</strong> | ||
</span> | ||
<span | ||
className="empty" /> | ||
</span> | ||
<span | ||
className="empty" /> | ||
</div> | ||
</div> | ||
</BasicPure> | ||
</ClassWithDirectPure> | ||
`; | ||
|
||
exports[`test converts basic class mount 1`] = ` | ||
<BasicClass | ||
className="class"> | ||
<div | ||
className="basic-class class" | ||
onClick={[Function]}> | ||
<div | ||
className="group" | ||
id="group-id"> | ||
<span> | ||
<strong> | ||
Hello! | ||
</strong> | ||
</span> | ||
<span | ||
className="empty" /> | ||
</div> | ||
</div> | ||
</BasicClass> | ||
`; | ||
|
||
exports[`test converts basic pure mount 1`] = ` | ||
<BasicPure | ||
className="pure"> | ||
<div | ||
className="basic-pure pure" | ||
onClick={[Function]}> | ||
<div | ||
className="group" | ||
id="group-id"> | ||
<span> | ||
<strong> | ||
Hello! | ||
</strong> | ||
</span> | ||
<span | ||
className="empty" /> | ||
</div> | ||
</div> | ||
</BasicPure> | ||
`; | ||
|
||
exports[`test skips undefined props 1`] = ` | ||
<BasicWithUndefined> | ||
<button> | ||
Hello | ||
</button> | ||
</BasicWithUndefined> | ||
`; |
Oops, something went wrong.