Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for compatibility with Jest 22.0.0 #3

Merged
merged 2 commits into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ through the code to know _what_ caused the class name to change.
This allows your snapshots to look more like:

```html
.jsxstyle-0 {color:red;display:block;}
._15clmrq {
color:red;
display:block;
}

<h1
class="jsxstyle-0"
class="_15clmrq"
>
Hello World
</h1>
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
"author": "Jared Palmer <jared@palmer.net> (http://jaredpalmer.com/)",
"license": "MIT",
"dependencies": {
"jest-diff": "^19.0.0",
"jest-snapshot": "^19.0.2",
"jsxstyle": "2.0.0"
"jest-diff": "22.0.0",
"jest-snapshot": "22.0.0",
"jsxstyle": "2.0.7"
},
"devDependencies": {
"babel-cli": "^6.23.0",
Expand All @@ -37,7 +37,7 @@
"enzyme": "^2.7.1",
"enzyme-to-json": "^1.5.0",
"husky": "^0.13.2",
"jest-cli": "^19.0.2",
"jest-cli": "22.0.0",
"lint-staged": "^3.3.1",
"prettier": "^1.5.3",
"react": "^15.4.2",
Expand Down
124 changes: 61 additions & 63 deletions src/__snapshots__/serializer.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,72 +1,12 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Snapshot Serializer does not interfere with non jsxstyle components 1`] = `


<div>
Hello World, this is my first jsxstyle component!
</div>
`;

exports[`Snapshot Serializer handles children 1`] = `
._1jmy8or {
color: orange;
display: block;
}
._15clmrq {
display: block;
margin: 4rem;
}


<div
className="_1jmy8or"
style={undefined}
>
<div
className="_15clmrq"
style={undefined}
>
Hello World, this is my first jsxstyle component!
</div>
</div>
`;

exports[`Snapshot Serializer react-test-renderer 1`] = `
._1d79ojo {
background: white;
color: red;
display: block;
margin: 1rem;
}


<div
className="_1d79ojo"
style={undefined}
>
Hello World, this is my first jsxstyle component!
</div>
`;

exports[`Snapshot Serializer works when root element is not a jsxstyle element 1`] = `
._18ai6h8 {
color: black;
display: block;
}


<div>
<div
className="_18ai6h8"
style={undefined}
>
Hello World, this is my first jsxstyle component!
</div>
</div>
`;

exports[`enzyme.mount 1`] = `
exports[`Snapshot Serializer enzyme: enzyme.mount 1`] = `
._1cvnte8 {
color: green;
display: block;
Expand Down Expand Up @@ -98,7 +38,7 @@ exports[`enzyme.mount 1`] = `
</Block>
`;

exports[`enzyme.render 1`] = `
exports[`Snapshot Serializer enzyme: enzyme.render 1`] = `
._1cvnte8 {
color: green;
display: block;
Expand All @@ -120,7 +60,7 @@ exports[`enzyme.render 1`] = `
</div>
`;

exports[`enzyme.shallow 1`] = `
exports[`Snapshot Serializer enzyme: enzyme.shallow 1`] = `
._1cvnte8 {
color: green;
display: block;
Expand All @@ -138,3 +78,61 @@ exports[`enzyme.shallow 1`] = `
</Block>
</div>
`;

exports[`Snapshot Serializer handles children 1`] = `
._1jmy8or {
color: orange;
display: block;
}
._15clmrq {
display: block;
margin: 4rem;
}


<div
className="_1jmy8or"
style={undefined}
>
<div
className="_15clmrq"
style={undefined}
>
Hello World, this is my first jsxstyle component!
</div>
</div>
`;

exports[`Snapshot Serializer react-test-renderer 1`] = `
._1d79ojo {
background: white;
color: red;
display: block;
margin: 1rem;
}


<div
className="_1d79ojo"
style={undefined}
>
Hello World, this is my first jsxstyle component!
</div>
`;

exports[`Snapshot Serializer works when root element is not a jsxstyle element 1`] = `
._18ai6h8 {
color: black;
display: block;
}


<div>
<div
className="_18ai6h8"
style={undefined}
>
Hello World, this is my first jsxstyle component!
</div>
</div>
`;
12 changes: 7 additions & 5 deletions src/serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ cache.injectOptions({
onInsertRule: rule => {
styles += rule + '\n';
},
pretty: true
})
pretty: true,
});

function createSerializer(injector) {
function test(val) {
Expand All @@ -16,12 +16,14 @@ function createSerializer(injector) {
);
}

function print(val, printer) {
function print(val, serialize) {
val.withStyles = true;

const prettyPrinted = `${styles}\n\n${printer(val)}`;

const stylesToPrint = styles === '' ? styles : `${styles}\n\n`;
styles = '';

const prettyPrinted = `${stylesToPrint}${serialize(val)}`;

cache.reset();
return prettyPrinted;
}
Expand Down
Loading