Socket
Book a DemoInstallSign in
Socket

@smartlyio/oats-fast-check

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smartlyio/oats-fast-check

fast-check value generator for smartlyio/oats types

7.6.1
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Fast-check generators for smartlyio/oats

Fast-check generators for @smartlyio/oats types.

generator.named

Generate values of named types from the openapi specification. Here using a jest wrapper.

// yarn jest examples/type.spec.ts
import * as fc from 'fast-check';
import { generator } from '../src/index';
import * as runtime from '@smartlyio/oats-runtime';
import * as types from '../tmp/openapi.types.generated';

describe('value generation', () => {
  it ('generates valid values', () =>
    fc.assert(
      fc.property(
        // create a fast-check Arbitrary from the type structure
        generator.named(types.typeTestObject),
        (value: types.TestObject) => {
          // assert that all the generated values are valid
          const json = runtime.valueClass.toJSON(value);
          types.typeTestObject.maker(json).success();
        }
      )
  ))
});

generator.override

Override automatic generators globally with a custom Arbitrary

// yarn jest examples/override.spec.ts
import * as fc from 'fast-check';
import { generator } from '../src/index';
import * as types from '../tmp/openapi.types.generated';

describe('overriding generators', () => {
  it ('.override provides custom generator for type', () => {
    generator.override(types.typeTestTarget, fc.constant('overridden value'));
    fc.assert(
      fc.property(
        generator.named(types.typeTestTarget),
        (value: types.TestTarget) => {
          expect(value).toEqual('overridden value');
        }
      )
    );
  })

  it ('.clear removes override', () => {
    generator.override(types.typeTestTarget, fc.constant('overridden value'));
    generator.clear(types.typeTestTarget);
    fc.assert(
      fc.property(
        generator.named(types.typeTestTarget),
        (value: types.TestTarget) => {
          expect(value).not.toEqual('overridden value');
        }
      )
    );
  })
});

Keywords

oats

FAQs

Package last updated on 23 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.