json-chaos
v1.1.0
Published
A tool that randomly changes properties in objects
Downloads
3
Maintainers
Readme
JSON Chaos
Inspired by Chaos Monkey, JSON Chaos is a tool that randomly changes properties in objects. It is useful to validate a strict API:
import chaos from 'json-chaos';
const person = { name: 'John', age: 21 };
console.log(chaos(person));
// { name: 45423, age: true }
console.log(chaos(person));
// { name: 1673, age: 'hello' }
console.log(person); // No mutations
// { name: 'John', age: 21 }
It ensures these:
- The Object retains the same structure
- The properties (leafs) change their type
By default it will change up to 100 properties, you can modify this with the second argument:
const person = { name: 'John', age: 21 };
// Change only one of those properties
chaos(person, 1);
Useful for testing:
// A valid schema
import demo from './demo';
it('has a strict schema', () => {
expect(valid(demo)).toBe(true);
const modified = chaos(demo);
expect(valid(chaos(demo))).toBe(false);
});