stub-obj-proxy

1.0.0 • Public • Published

stub-obj-proxy

Make stub objects using Proxies, supporting null-safe deep path access, function calls, for loops, etc.

Useful for mocking out objects in tests, e.g., the window global.

import stubObjProxy from 'stub-obj-proxy'
 
global.window = stubObjProxy()

Other file:

console.log(window.a.b.c)
 
window.a.b.c = 'foo' // Note: sets do not persist
 
for (let e in window.a.b.c) {
  console.log(e)
}
 
window.a.b.c.hasOwnProperty('ok') // true
 
'ok' in window.a.b.c // true

Readme

Keywords

none

Package Sidebar

Install

npm i stub-obj-proxy

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • andersdjohnson