Make the README example run to the end
It needs zod, which this package does not depend on, so the import now says to install it. assertFields threw on the drift the example shows on purpose, which stopped the script before the coverage part; it is now a commented alternative to the expectFields report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
61b28ce918
commit
339129990c
@@ -53,7 +53,7 @@ assessed. Reports use the `@extant2000/evidence-record` format.
|
|||||||
|
|
||||||
```ts
|
```ts
|
||||||
import { assertShape, expectFields, assertFields, formatFields, coverage, formatCoverage } from '@extant2000/contract-check'
|
import { assertShape, expectFields, assertFields, formatFields, coverage, formatCoverage } from '@extant2000/contract-check'
|
||||||
import { z } from 'zod' // or any parser with a zod-style safeParse
|
import { z } from 'zod' // npm install zod, or use any parser with a zod-style safeParse
|
||||||
|
|
||||||
// 1. Response shape
|
// 1. Response shape
|
||||||
const payload: unknown = { id: 'm1', name: 'Survey' } // e.g. a parsed response body
|
const payload: unknown = { id: 'm1', name: 'Survey' } // e.g. a parsed response body
|
||||||
@@ -68,7 +68,7 @@ const expectations = [
|
|||||||
]
|
]
|
||||||
const result = expectFields(subscription, expectations)
|
const result = expectFields(subscription, expectations)
|
||||||
console.log(formatFields(result, { context: 'stripe.subscriptions.create', expectations }))
|
console.log(formatFields(result, { context: 'stripe.subscriptions.create', expectations }))
|
||||||
assertFields(subscription, expectations, 'stripe.subscriptions.create') // or throw
|
// assertFields(subscription, expectations, 'stripe.subscriptions.create') // throws ContractDriftError here instead
|
||||||
|
|
||||||
// 3. Coverage against a floor
|
// 3. Coverage against a floor
|
||||||
const c = coverage(['GET /a', 'GET /b', 'POST /c', 'GET /d'], ['GET /a', 'GET /b', 'POST /c'], 80)
|
const c = coverage(['GET /a', 'GET /b', 'POST /c', 'GET /d'], ['GET /a', 'GET /b', 'POST /c'], 80)
|
||||||
|
|||||||
Reference in New Issue
Block a user