tap-plugin-matchjsonschema
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

tap-plugin-matchjsonschema

Plugin for the TAP test framework. This plugin verify if the value matches the provided JSON schema.

To install the plugin, run the following command:

npx tap plugin add tap-plugin-matchjsonschema

Usage example:

import t from 'tap'

const schema = {
  type: 'object',
  required: ['id', 'name', 'username', 'email', 'createdAt', 'updatedAt'],
  properties: {
    id: { type: 'number', minimum: 1 },
    name: { type: 'string', maxLength: 100 },
    username: { type: 'string', maxLength: 100 },
    email: { type: 'string', maxLength: 100, format: 'email' },
    createdAt: { type: 'string', format: 'date-time' },
    updatedAt: { type: 'string', format: 'date-time' }
  },
  additionalProperties: false
}

t.test('success', t => {
  const data = {
    id: 1,
    name: 'Sheldon Bahringer',
    username: 'Sheldon52',
    email: 'Sheldon_Bahringer6@yahoo.com',
    createdAt: '2023-07-01 00:00:00',
    updatedAt: '2023-07-01 00:00:00'
  }
  t.matchJsonSchema(data, schema)
  t.end()
})

Package Sidebar

Install

npm i tap-plugin-matchjsonschema

Weekly Downloads

7

Version

1.0.1

License

BlueOak-1.0.0

Unpacked Size

21 kB

Total Files

29

Last publish

Collaborators

  • ns16