Skip to content

franciscop/json-chaos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON Chaos npm install json-chaos test badge

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);
});

About

A tool that randomly changes properties in objects

Resources

License

Stars

Watchers

Forks

Packages

No packages published