Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/typed-sigterm/any
Mock anything with a Magic Object.
https://github.com/typed-sigterm/any
chai jest mock testing unit-testing vitest
Last synced: 16 days ago
JSON representation
Mock anything with a Magic Object.
- Host: GitHub
- URL: https://github.com/typed-sigterm/any
- Owner: typed-sigterm
- License: mit
- Created: 2024-11-09T16:30:17.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-11-22T13:51:50.000Z (2 months ago)
- Last Synced: 2024-11-22T14:37:39.854Z (2 months ago)
- Topics: chai, jest, mock, testing, unit-testing, vitest
- Language: TypeScript
- Homepage:
- Size: 48.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Any
Mock anything with a Magic Object, no more `TypeError: Cannot read properties of undefined`s.
## Usage
```ts
import { assert } from '@std/assert';
import { any, isAny } from '@typed-sigterm/any';// Create a Any.
const thing = any();// Check if anything is a Any.
assert(isAny(thing) === true);
assert(isAny(0) === false);// You can access any property, returns a new Any.
assert(isAny(thing.foo));
assert(!Object.is(thing.foo, thing));// You can set any property, nothing will happen.
thing.foo = 'bar';
assert(isAny(thing.foo));// You can delete any property, nothing will happen.
delete thing.foo;
assert(isAny(thing.foo));// ... more examples can be found in the test file:
// https://github.com/typed-sigterm/any/blob/latest/__tests__/mod.spec.ts
```## Compatibility
This module depends on `Proxy` support, see [Can I use](https://caniuse.com/proxy) for compatibility information.