Home Reference Source Test
public class | source

Assert

You can directly use an instance of this class. assert

This Assert class provides asserting methods based on builtin generate-schema, and schema checking ajv

Example:

import { assert } from 'causal-net.utils';
assert.seemMatchSample([2,2,3], [1,2,3], 'validate sample');
assert.seemMatchSample('sample text', 'pattern text', 'validate sample');
assert.seemMatchSample( { 'text' : 'pattern text 1', 'number' : 1123 }, 
                        { 'text' : 'pattern text', 'number' : 1123 } , 'validate sample');
try{
    assert.seemMatchSample(['2',2,3], [1,2,3], 'validate sample');
}
catch(err){
    //error due to mismatch schema
    console.log(err.message);
};
class A{};
let a = new A();
assert.beInstanceOf(a, A);
try{
    assert.beInstanceOf('1', A);
}
catch(err){
    console.log(err.message);
}

Constructor Summary

Public Constructor
public

Creates an instance of assert.

Member Summary

Public Members
public
public
Private Members
private

assert: Object

Method Summary

Public Methods
public

beInstanceOf(instance: Object , targetClass: Class )

assert object to be instance of class

public

seemMatchSample(value: Any , sample: Any , name: String )

Try to check if the sample pattern matchs with input value pattern.

Public Constructors

public constructor() source

Creates an instance of assert.

Public Members

public Validator: * source

public generateSchema: * source

Private Members

private assert: Object source

Test:

Public Methods

public beInstanceOf(instance: Object , targetClass: Class ) source

assert object to be instance of class

Params:

NameTypeAttributeDescription
instance Object
targetClass Class

public seemMatchSample(value: Any , sample: Any , name: String ) source

Try to check if the sample pattern matchs with input value pattern. Since the auto-learnt sample pattern could be incompleted, this function usage should follow the examples.

Params:

NameTypeAttributeDescription
value Any

input value

sample Any

sample value pattern

name String
  • optional
  • default: 'sample'

value name