Skip to content

Commit 85a1dad

Browse files
committed
Support shallow assertions of components with complex props
1 parent 3892e97 commit 85a1dad

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"preact": "^5.6.0"
3636
},
3737
"dependencies": {
38-
"preact-render-to-string": "^2.7.0"
38+
"preact-render-to-string": "^3.0.0"
3939
},
4040
"greenkeeper": {
4141
"ignore": [

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export const options = {};
1010
// options to pass to renderToString() when doing a deep comparison
1111
const RENDER_OPTS = {
1212
sortAttributes: true,
13+
xml: true,
14+
jsx: true,
1315
pretty: true
1416
};
1517

test/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,17 @@ describe('preact-jsx-chai', () => {
7878
expect(<Outer />).to.eql(<span b1="b">1</span>);
7979
expect(<Outer a />).not.to.eql(<Outer b />);
8080
});
81+
82+
it('should shallow-compare components with complex props', () => {
83+
let counter = 0;
84+
const Outer = () => <Inner b={['a','b','c']} c={{ foo:'bar' }} />;
85+
const Inner = ({ b }) => <span b1={b+''}>{++counter}</span>;
86+
expect(<Outer a />).to.equal(<Inner b={['a','b','c']} c={{ foo:'bar' }} />);
87+
88+
// make sure inequality within an attribute generates a failed assertion:
89+
expect( () => {
90+
expect(<Outer a />).to.equal(<Inner b={['a','c','c']} c={{ foo:'bar' }} />);
91+
}).to.throw(/"b".*?"c"/); // really loose here, but it would fail if the assertion stopped working
92+
});
8193
});
8294
});

0 commit comments

Comments
 (0)