Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for createTests #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ const my_patch = createPatch(input, output, myDiff)
```
This will short-circuit on encountering an instance of `MyObject`, but otherwise recurse as usual.

### `createTest(input: any, patch: Operation[]): Operation[]`

Returns a list of `test` JSON Patch operations to verify that
existing values in an object are identical to the those captured at some
checkpoint (whenever this function is called).

The resulting operations don't modify the object. You can use the resulting
operations to validate that an object is in the expected state before applying a
patch.

Sample usage:

```js
const patch = rfc6902.createPatch({first: 'Chris', last: 'Brown'}, {first: 'Chris', last: 'Smith'});
const tests = rfc6902.createTests({first: 'Chris', last: 'Brown'}, patch);
const problems = rfc6902.applyPatch({first: 'Chris', last: 'Cook'}, tests).filter(i => i != null);
console.log([problem]);
// [ Error [TestError]: Test failed: Cook != Brown ]
```

### `Operation`

```typescript
Expand Down