-
Notifications
You must be signed in to change notification settings - Fork 25
Include non-enumerable properties #482
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
Merged
alexjeffburke
merged 10 commits into
unexpectedjs:master
from
alexjeffburke:feature/includeNonEnumerableProperties
Jun 29, 2018
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9337c5a
Avoid deferring to the base type for object equality.
alexjeffburke 8ecdf6e
Switch to retrieving all properties from objects and fixup Error.
alexjeffburke 5ec7dc9
Catch up with enumerable properties being included.
alexjeffburke 36b828c
Remove unnecessary loop given non-enumerable keys are now included.
alexjeffburke 4557f85
Simplify key handling in "to satisfy" given the enumerability changes.
alexjeffburke 6fb0a96
Rework the special case handling of value side expect.it.
alexjeffburke 763607a
Handle errors with additional non-enumerable properties via bluebird.
alexjeffburke fa0be50
Work around issues with node 0.10
papandreou 695226a
Fix documentation tests
papandreou 4683469
Fix prettier 1.13 nit
papandreou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1796,27 +1796,35 @@ module.exports = expect => { | |
| if (valueType.is('array-like') && !subjectIsArrayLike) { | ||
| expect.fail(); | ||
| } | ||
| const promiseByKey = {}; | ||
| const keys = valueType.getKeys(value); | ||
|
|
||
| const subjectKeys = subjectType.getKeys(subject); | ||
| const valueKeys = valueType.getKeys(value); | ||
| // calculate the unique keys early given enumerability no | ||
| // longer affects what is included in the list of keys | ||
| const uniqueKeys = subjectType.uniqueKeys(subjectKeys, valueKeys); | ||
|
|
||
| if (!subjectIsArrayLike) { | ||
| // Find all non-enumerable subject keys present in value, but not returned by subjectType.getKeys: | ||
| keys.forEach(key => { | ||
| if ( | ||
| Object.prototype.hasOwnProperty.call(subject, key) && | ||
| subjectKeys.indexOf(key) === -1 | ||
| ) { | ||
| subjectKeys.push(key); | ||
| const promiseByKey = {}; | ||
| let forceExhaustivelyComparison = false; | ||
| uniqueKeys.forEach((key, index) => { | ||
| const subjectKey = subjectType.valueForKey(subject, key); | ||
| const valueKey = valueType.valueForKey(value, key); | ||
| const valueKeyType = expect.findTypeOf(valueKey); | ||
| const isDefinedSubjectKey = typeof subjectKey !== 'undefined'; | ||
| const isDefinedValueKey = typeof valueKey !== 'undefined'; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't |
||
|
|
||
| if (expect.flags.exhaustively) { | ||
| if (valueKeyType.is('expect.it') && !isDefinedSubjectKey) { | ||
| // ensure value only expect.it key is marked missing | ||
| forceExhaustivelyComparison = true; | ||
| } | ||
| }); | ||
| } | ||
| } else { | ||
| if (isDefinedSubjectKey && !isDefinedValueKey) { | ||
| // ignore subject only keys unless we are being exhaustive | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| keys.forEach((key, index) => { | ||
| promiseByKey[key] = expect.promise(() => { | ||
| const subjectKey = subjectType.valueForKey(subject, key); | ||
| const valueKey = valueType.valueForKey(value, key); | ||
| const valueKeyType = expect.findTypeOf(valueKey); | ||
| if (valueKeyType.is('expect.it')) { | ||
| expect.context.thisObject = subject; | ||
| return valueKey(subjectKey, expect.context); | ||
|
|
@@ -1831,25 +1839,8 @@ module.exports = expect => { | |
| return expect.promise | ||
| .all([ | ||
| expect.promise(() => { | ||
| if (expect.flags.exhaustively) { | ||
| const nonOwnKeysWithDefinedValues = keys.filter( | ||
| key => | ||
| !Object.prototype.hasOwnProperty.call(subject, key) && | ||
| typeof subjectType.valueForKey(subject, key) !== 'undefined' | ||
| ); | ||
| const valueKeysWithDefinedValues = keys.filter( | ||
| key => typeof valueType.valueForKey(value, key) !== 'undefined' | ||
| ); | ||
| const subjectKeysWithDefinedValues = subjectKeys.filter( | ||
| key => | ||
| typeof subjectType.valueForKey(subject, key) !== 'undefined' | ||
| ); | ||
| expect( | ||
| valueKeysWithDefinedValues.length - | ||
| nonOwnKeysWithDefinedValues.length, | ||
| 'to equal', | ||
| subjectKeysWithDefinedValues.length | ||
| ); | ||
| if (forceExhaustivelyComparison) { | ||
| throw new Error('exhaustive comparison failure'); | ||
| } | ||
| }), | ||
| expect.promise.all(promiseByKey) | ||
|
|
@@ -1860,16 +1851,13 @@ module.exports = expect => { | |
| diff(output, diff, inspect, equal) { | ||
| output.inline = true; | ||
| const subjectIsArrayLike = subjectType.is('array-like'); | ||
| const valueKeys = valueType.getKeys(value); | ||
| const keys = subjectType | ||
| .uniqueKeys(subjectKeys, valueKeys) | ||
| .filter(key => { | ||
| // Skip missing keys expected to be missing so they don't get rendered in the diff | ||
| return ( | ||
| subjectType.hasKey(subject, key) || | ||
| typeof valueType.valueForKey(value, key) !== 'undefined' | ||
| ); | ||
| }); | ||
| // Skip missing keys expected to be missing so they don't get rendered in the diff | ||
| const keys = uniqueKeys.filter(key => { | ||
| return ( | ||
| subjectType.hasKey(subject, key) || | ||
| typeof valueType.valueForKey(value, key) !== 'undefined' | ||
| ); | ||
| }); | ||
| const prefixOutput = subjectType.prefix( | ||
| output.clone(), | ||
| subject | ||
|
|
@@ -2354,14 +2342,19 @@ module.exports = expect => { | |
| } | ||
| }); | ||
| }, | ||
| err => | ||
| err => { | ||
| if (err.isOperational && !err.propertyIsEnumerable('isOperational')) { | ||
| delete err.isOperational; | ||
| } | ||
|
|
||
| expect.withError( | ||
| () => expect.shift(err), | ||
| e => { | ||
| e.originalError = err; | ||
| throw e; | ||
| } | ||
| ) | ||
| ); | ||
| } | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhh I know this is my mistake, but I think things will be much more clear if we called subject actual and value expected in this method. We can always fix that later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe subject and spec.