Skip to content

Commit

Permalink
Allow for global configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
lelandrichardson committed Sep 26, 2017
1 parent 9930f3e commit bb4c6b6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/enzyme/src/ReactWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
nodeEqual,
nodeMatches,
getAdapter,
makeOptions,
sym,
privateSet,
cloneElement,
Expand Down Expand Up @@ -66,12 +67,13 @@ function filterWhereUnwrapped(wrapper, predicate) {
* @class ReactWrapper
*/
class ReactWrapper {
constructor(nodes, root, options = {}) {
constructor(nodes, root, passedOptions = {}) {
if (!global.window && !global.document) {
throw new Error(
'It looks like you called `mount()` without a global document being loaded.',
);
}
const options = makeOptions(passedOptions);

if (!root) {
privateSet(this, UNRENDERED, nodes);
Expand Down
6 changes: 4 additions & 2 deletions packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isCustomComponentElement,
ITERATOR_SYMBOL,
getAdapter,
makeOptions,
sym,
privateSet,
cloneElement,
Expand Down Expand Up @@ -108,8 +109,9 @@ function getRootNode(node) {
* @class ShallowWrapper
*/
class ShallowWrapper {
constructor(nodes, root, options = {}) {
validateOptions(options);
constructor(nodes, root, passedOptions = {}) {
validateOptions(passedOptions);
const options = makeOptions(passedOptions);
if (!root) {
privateSet(this, ROOT, this);
privateSet(this, UNRENDERED, nodes);
Expand Down
7 changes: 7 additions & 0 deletions packages/enzyme/src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ export function getAdapter(options = {}) {
return adapter;
}

export function makeOptions(options) {
return {
...configuration.get(),
...options,
};
}

export function isCustomComponentElement(inst, adapter) {
return !!inst && adapter.isValidElement(inst) && typeof inst.type === 'function';
}
Expand Down

0 comments on commit bb4c6b6

Please sign in to comment.