Skip to content

Commit

Permalink
Simplified copyProps functions in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnaxsom committed Oct 23, 2018
1 parent b9e7fec commit fe5b22d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
11 changes: 4 additions & 7 deletions docs/guides/jsdom.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;

function copyProps(src, target) {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === 'undefined')
.reduce((result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(src, prop),
}), {});
Object.defineProperties(target, props);
Object.defineProperties(target, {
...Object.getOwnPropertyDescriptors(src),
...Object.getOwnPropertyDescriptors(target)
});
}

global.window = window;
Expand Down
14 changes: 4 additions & 10 deletions docs/guides/react-native.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,10 @@ const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;

function copyProps(src, target) {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === 'undefined')
.reduce(
(result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(src, prop),
}),
{},
);
Object.defineProperties(target, props);
Object.defineProperties(target, {
...Object.getOwnPropertyDescriptors(src),
...Object.getOwnPropertyDescriptors(target)
});
}

global.window = window;
Expand Down
8 changes: 4 additions & 4 deletions packages/enzyme-example-mocha/test/.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;

function copyProps(src, target) {
const props = Object.getOwnPropertyNames(src)
.filter(prop => typeof target[prop] === 'undefined')
.map(prop => Object.getOwnPropertyDescriptor(src, prop));
Object.defineProperties(target, props);
Object.defineProperties(target, {
...Object.getOwnPropertyDescriptors(src),
...Object.getOwnPropertyDescriptors(target)
});
}

global.expect = expect;
Expand Down

0 comments on commit fe5b22d

Please sign in to comment.