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

Avoid in-place mutation of the attributes of Router's children #169

Merged
merged 6 commits into from
Apr 9, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
}
},
"globals": {
"chai": true,
"sinon": true,
"expect": true
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"minify": "uglifyjs $npm_package_main -cm -o $npm_package_minified_main -p relative --in-source-map ${npm_package_main}.map --source-map ${npm_package_minified_main}.map",
"size": "size=$(gzip-size $npm_package_minified_main) && echo \"gzip size: $size / $(pretty-bytes $size)\"",
"test": "npm-run-all lint build test:karma",
"lint": "eslint {src,test}",
"lint": "eslint {src,test,test_helpers}",
"test:karma": "karma start --single-run",
"test:watch": "karma start",
"prepublish": "npm-run-all build test",
Expand Down
12 changes: 12 additions & 0 deletions test_helpers/assert-clone-of.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { cloneElement } from 'preact';
Copy link
Contributor Author

@rmacklin rmacklin Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this file in a new test_helpers directory, because it's not a test itself, but it's imported by some of the tests. If you'd prefer it live within the test directory, or a subdirectory inside test (e.g. test/helpers), I'd be happy to move it there. We'll just need to modify files: ['test/**/*.js'] in the karma config to exclude this if we move it inside test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with how you laid it out :)


export default function assertCloneOf({ Assertion }) {
if (Assertion.__assertCloneOfMounted === true) return;
Assertion.__assertCloneOfMounted = true;

Assertion.addMethod('cloneOf', function(routeJsx, { matches = {}, url = this._obj.attributes.path } = {}) {
const vnode = this._obj;
const clonedRoute = cloneElement(routeJsx, { url, matches, ...matches });
new chai.Assertion(vnode).to.be.eql(clonedRoute);
});
}