json-chaos

1.1.0 • Public • Published

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

/json-chaos/

    Package Sidebar

    Install

    npm i json-chaos

    Weekly Downloads

    4

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    4.8 kB

    Total Files

    4

    Last publish

    Collaborators

    • franciscop