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. |
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 Methods
public beInstanceOf(instance: Object , targetClass: Class ) source
assert object to be instance of class
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
value | Any | input value |
|
sample | Any | sample value pattern |
|
name | String |
|
value name |