-
-
Notifications
You must be signed in to change notification settings - Fork 698
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #721 from meeber/property-validation
Throw when non-existent property is read
- Loading branch information
Showing
8 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/*! | ||
* Chai - proxify utility | ||
* Copyright(c) 2012-2014 Jake Luer <jake@alogicalparadox.com> | ||
* MIT Licensed | ||
*/ | ||
|
||
/** | ||
* # proxify(object) | ||
* | ||
* Return a proxy of given object that throws an error when a non-existent | ||
* property is read. (If Proxy or Reflect is undefined, then return object | ||
* without modification.) | ||
* | ||
* @param {Object} obj | ||
* @namespace Utils | ||
* @name proxify | ||
*/ | ||
|
||
module.exports = function proxify (obj) { | ||
if (typeof Proxy === 'undefined' || typeof Reflect === 'undefined') | ||
return obj; | ||
|
||
return new Proxy(obj, { | ||
get: function getProperty (target, property) { | ||
// Don't throw error on Symbol properties such as Symbol.toStringTag, nor | ||
// on .then because it's necessary for promise type-checking. | ||
if (typeof property === 'string' && | ||
property !== 'then' && | ||
!Reflect.has(target, property)) | ||
throw Error('Invalid Chai property: ' + property); | ||
|
||
return target[property]; | ||
} | ||
}); | ||
}; |
This file contains 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 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 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