@angular-package/testing v2.0.0-rc
Packages
Package | Description | Status |
---|---|---|
callback | Manages the callback function . | |
change-detection | Improves application performance. | |
component-loader | Handles dynamic loading components. | |
core | Core features. | |
error | Manages an Error . | |
name | The name with prefix and suffix. | |
preferences | Preferences, settings, options, configuration and setup in steps. | |
prism | Prism highlighter module. | |
property | Handles object properties. | |
range | The range between a minimum and maximum. | |
reactive | Automatize the process of creating some rxjs features. | |
storage | The storage of data under allowed names. | |
tag | Any tag with optional attributes. | |
testing | Support for testing other packages. | |
text | Text on the template with replaceable tags. | |
type | Common types, type guards, and type checkers. | |
ui | User interface. | In Progress |
wrapper | Wrap the text with the opening and closing chars. |
Click on the package name to visit its GitHub page.
angular-package/testing
Support for testing other packages.
Table of contents
Basic concepts
Checks
It's to check the provided value to be the same as expected.
Type guard (constrain)
Constrains the parameter type to not let input unexpected value in the code editor.
Guards
It's a combination of both above, constrains the type of the parameter in the code editor, and checks its provided argument.
Defines
Returns defined value from a method of an object.
Defines new value in an object and returns a defined value.
Gets
Returns a value from an object.
Sets
Adds or updates an element with a specified key and a value to an object and returns an object.
Skeleton
This package was built by the library skeleton which was generated with Angular CLI version 12.2.5.
Copy this package to the packages/testing
folder of the library skeleton then run the commands below.
Build
Run ng build testing
to build the package. The build artifacts will be stored in the dist/
directory.
Running unit tests
Run ng test testing
to execute the unit tests via Karma.
Installation
Install @angular-package/testing
package with command:
npm i --save @angular-package/testing
Api
// Main.
import {
// Class.
Testing,
TestingToBeMatchers,
} from '@angular-package/testing';
// Helper functions.
import {
// Function.
randomNumber,
randomString,
} from '@angular-package/testing';
// Helper constants.
import {
// Example class for testing.
TestingClass,
TestingPerson,
// Array.
TESTING_ARRAY_BIGINT,
TESTING_ARRAY_BOOLEAN,
TESTING_ARRAY_CLASS,
TESTING_ARRAY_FUNCTION,
TESTING_ARRAY_NULL,
TESTING_ARRAY_NUMBER,
TESTING_ARRAY_OBJECT_ONE,
TESTING_ARRAY_STRING,
TESTING_ARRAY_SYMBOL_NUMBER,
TESTING_ARRAY_SYMBOL_STRING,
TESTING_ARRAY_UNDEFINED,
// BigInt
TESTING_BIGINT,
// Class.
TESTING_CLASS,
TESTING_PERSON,
// Date.
TESTING_DATE,
// Boolean.
TESTING_FALSE,
TESTING_FALSE_INSTANCE,
TESTING_TRUE,
TESTING_TRUE_INSTANCE,
// Function.
TESTING_FUNCTION,
TESTING_FUNCTION_CONSTRUCTOR,
TESTING_FUNCTION_CONSTRUCTOR_PERSON,
// null.
TESTING_NULL,
// Number.
TESTING_NUMBER,
TESTING_NUMBER_CONSTRUCTOR,
TESTING_NUMBER_INSTANCE,
// Object.
TESTING_OBJECT,
// RegExp.
TESTING_REGEXP,
// String.
TESTING_STRING,
TESTING_STRING_CONSTRUCTOR,
TESTING_STRING_INSTANCE,
// Symbol.
TESTING_SYMBOL_NUMBER,
TESTING_SYMBOL_STRING,
// Undefined.
TESTING_UNDEFINED,
} from '@angular-package/testing';
import {
// Interface.
TestingObject,
TestingPersonShape
} from '@angular-package/testing';
Instance of
Possible names of javascript objects that can be checked by the instanceof
operator.
const value: any = new Object({});
value instanceof Array
value instanceof ArrayBuffer;
value instanceof Boolean;
value instanceof DataView;
value instanceof Date;
value instanceof Error;
value instanceof EvalError;
value instanceof Int16Array;
value instanceof Int32Array;
value instanceof Int8Array;
value instanceof Map;
value instanceof Promise;
value instanceof RangeError
value instanceof RangeError;
value instanceof ReferenceError;
value instanceof RegExp;
value instanceof Set;
value instanceof SharedArrayBuffer;
value instanceof SyntaxError;
value instanceof Float32Array;
value instanceof Float64Array;
value instanceof Function;
value instanceof Number;
value instanceof Object;
value instanceof String;
value instanceof Storage;
value instanceof TypeError;
value instanceof Uint16Array;
value instanceof Uint32Array;
value instanceof Uint8Array;
value instanceof Uint8ClampedArray;
value instanceof URIError;
value instanceof WeakMap;
value instanceof WeakSet;
Testing
Testing
Simple class
to support testing.
Methods prefixed with the
toBe
aren't working with thebeforeEach()
function of jasmine.
Static methods:
Testing. | Description |
---|---|
defineDescribe() | Defines the wrapper function of the describe() function of jasmine with the ability to decide its execution. |
defineIt() | Defines the wrapper function of the it() function of jasmine with the ability to decide its execution. |
Constructor:
Testing | Description |
---|---|
constructor | Creates an instance with setting for global allow executing of the describe() and it() methods, and optionally sets the list of allowed executable tests (those that execute even on the disallowed state). |
Instance public methods:
Testing.prototype. | Description |
---|---|
describe() | Executes defined describe() function of jasmine on a state true from the execute . |
it() | Executes defined it() function of jasmine on a state true from the execute . |
Testing.prototype. | Executes the spec on a state true from the execute expecting the provided value to |
---|---|
toBe() | be the given expected value. |
toBeBigInt() | be a bigint type on the given expected state of true . |
toBeBooleanType() | be of a boolean type on the given expected state of true . |
toBeClass() | be a class on the given expected state of true . |
toBeInstanceOfArray() | be an instance of an Array on the given expected state of true . |
toBeInstanceOfBoolean() | be an instance of Boolean on the given expected state of true . |
toBeInstanceOfDate() | be an instance of Date on the given expected state of true . |
toBeInstanceOfError() | be an instance of an Error on the given expected state of true . |
toBeInstanceOfFunction() | be an instance of a Function on the given expected state of true . |
toBeInstanceOfMap() | be an instance of a Map on the given expected state of true . |
toBeInstanceOfNumber() | be an instance of a Number on the given expected state of true . |
toBeInstanceOfObject() | be an instance of an Object on the given expected state of true . |
toBeInstanceOfPromise() | be an instance of Promise on the given expected state of true . |
toBeInstanceOfRangeError() | be an instance of RangeError on the given expected state of true . |
toBeInstanceOfReferenceError() | be an instance of ReferenceError on the given expected state of true . |
toBeInstanceOfRegExp() | be an instance of RegExp on the given expected state of true . |
toBeInstanceOfSet() | be an instance of Set on the given expected state of true . |
toBeInstanceOfStorage() | be an instance of Storage on the given expected state of true . |
toBeInstanceOfString() | be an instance of a String on the given expected state of true . |
toBeInstanceOfSyntaxError() | be an instance of SyntaxError on the given expected state of true . |
toBeInstanceOfTypeError() | be an instance of TypeError on the given expected state of true . |
toBeInstanceOfURIError() | be an instance of URIError on the given expected state of true . |
toBeInstanceOfWeakSet() | be an instance of a WeakSet on the given expected state of true . |
toBeNull() | be null on the given expected state of true . |
toBeNumberType() | be of a number type on the given expected state of true . |
toBeStringType() | be of a string type on the given expected state of true . |
toEqual() | be equal to the given expected . |
Testing
static methods
Testing.defineDescribe()
Defines the wrapper function
of the describe()
function of jasmine with the ability to decide its execution.
static defineDescribe(
description: string,
specDefinitions: () => void
): (execute: boolean) => void {
return TestingDescribe.define(description, specDefinitions);
}
Parameters:
Name: type | Description |
---|---|
description: string | "Textual description of the group" - jasmine. |
specDefinitions: () => void | "Function for Jasmine to invoke that will define" - jasmine. |
Returns:
The return value is a function
that contains the describe()
function of jasmine with the ability to decide its execution.
Usage:
// Example usage.
// Object.
import { is } from '@angular-package/type';
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* Tests.
*/
const testingDescribe = Testing.defineDescribe('Primitives values', () => {
const numberSpec = Testing.defineIt('The value must be a number type', () => {
expect(is.number(5)).toBeTruthy();
}, 3000);
numberSpec(false); // Do not execute.
numberSpec(true); // Execute.
});
testingDescribe(false); // Do not execute.
testingDescribe(true); // Execute.
Testing.defineIt()
Defines the wrapper function
of the it()
function of jasmine with the ability to decide its execution.
static defineIt(
expectation: string,
assertion: jasmine.ImplementationCallback,
timeout?: number | undefined,
): (execute: boolean) => void {
return TestingIt.define(expectation, assertion, timeout);
}
Parameters:
Name: type | Description |
---|---|
description: string | "Textual description of the group" - jasmine. |
specDefinitions: () => void | "Function for Jasmine to invoke that will define" - jasmine. |
Returns:
The return value is a function
that contains the describe()
function of jasmine with the ability to decide its execution.
Usage:
// Example usage.
// Object.
import { is } from '@angular-package/type';
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* defineIt().
*/
testing.describe('defineIt()', () => {
const numberSpec = Testing.defineIt('The value must be a number type', () => {
expect(is.number(5)).toBeTruthy();
}, 3000);
numberSpec(false); // Do not execute.
numberSpec(true); // Execute.
});
Testing
constructor
Creates an instance with setting for global allow executing of the describe()
and it()
methods, and optionally sets the list of allowed executable tests (those that execute even on the disallowed state).
constructor(
allowDescribe: boolean,
allowIt: boolean,
executable?: ExecutableTests
) {
super(allowDescribe, allowIt, executable);
}
Parameters:
Name: type | Description |
---|---|
allowDescribe: boolean | Allow executing describe() methods. |
allowIt: boolean | Allow executing it() methods. |
executable?: ExecutableTests | An optional object with unique numbers of executable tests for describe() and it() method. |
Returns:
The return value is new instance of a Testing
.
Usage:
// Example usage.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(
true, // Allows executing the `describe()` method globally.
true, // Allows executing the `it()` method globally.
{
describe: [], // Executable unique numbers of `describe()` methods to execute when global executing is disallowed.
it: [], // Executable unique numbers of `it()` methods to execute when global executing is disallowed.
}
);
Example of using allow.
/**
* Initialize testing.
*/
const testing = new Testing(
false, // Disallows executing the `describe()` method globally.
false, // Disallows executing the `it()` method globally.
{
describe: [1, 2, 3, 5], // Executable unique numbers of `describe()` methods to execute when global executing is disallowed.
it: [1], // Executable unique numbers of `it()` methods inside the `describe()` to execute when global executing is disallowed.
}
);
testing.describe('[counter] First describe', () => {
testing
.it('[counter] First it() in first describe 1-1', () =>
expect(false).toBeFalse()
)
.it('[counter] Second it() in first describe 1-2', () =>
expect(true).toBeTrue()
)
.it('[counter] Second it() in first describe 1-3', () =>
expect(true).toBeTrue()
)
.it('[counter] Fourth it() in first describe() 1-4', () =>
expect(true).toBeTrue()
)
.describe('[counter] Second describe()', () => {
testing.it('[counter] First it() in second describe() 2-1', () =>
expect(true).toBeTrue()
);
})
.describe('[counter] Third describe()', () => {
testing.it('[counter] First it() in third describe() 3-1', () =>
expect(true).toBeTrue()
);
})
.describe('[counter] Fourth describe()', () => {
testing.it('[counter] First it() in fourth describe() 3-1', () =>
expect(true).toBeTrue()
);
});
});
testing.describe('[counter] Fifth describe', () =>
testing.it('[counter] First it() in fifth describe 5-1', () =>
expect(false).toBeFalse()
)
);
/*
Karma returns
1 First describe
1 First it() in first describe 1-1
3 Third describe()
1 First it() in third describe() 3-1
2 Second describe()
1 First it() in second describe() 2-1
5 Fifth describe
1 First it() in fifth describe 5-1
*/
Testing
instance methods
Testing.prototype.describe()
Executes defined describe()
function of jasmine on provided state true
from the execute
, and resets the counter to 0
.
public describe(
description: string,
specDefinitions: () => void,
execute?: boolean
): this {
this.#testingIt.resetCounter();
this.#testingDescribe.describe(description, specDefinitions, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
description: string | "Textual description of the group" with an optional its unique number inside the describe when adding [counter] . |
specDefinitions: () => void | "Function for Jasmine to invoke that will define inner suites a specs". |
execute: boolean | A boolean type value to decide whether or not execute defined describe() of jasmine function. |
Returns:
The return value is an instance of Testing
.
Usage:
// Example usage.
// Object.
import { is } from '@angular-package/type';
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* describe().
*/
testing.describe(
'[counter] describe()',
() => {},
true // Whether or not execute suite
);
Testing.prototype.it()
Executes defined it()
function of jasmine on provided state true
from the execute
.
public it(
expectation: string,
assertion: jasmine.ImplementationCallback,
execute?: boolean
): this {
this.#testingIt.it(expectation, assertion, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
description: string | "Textual description of what this spec is checking" with an optional its unique number when adding [counter] . |
specDefinitions: () => void | "Function that contains the code of your test. If not provided the test will be pending.". |
execute: boolean | A boolean type value to decide whether or not execute defined it() of jasmine function. |
Returns:
The return value is an instance of Testing
.
Usage:
// Example usage.
// Object.
import { is } from '@angular-package/type';
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* it().
*/
testing.describe(
'[counter] describe()',
() => testing.it('[counter] it()', () => {
expect(true).toBeTruthy();
},
true // Whether or not execute spec.
),
true // Whether or not execute suite.
);
Testing.prototype.toBe()
Executes the spec on a state true
from the execute
expecting the provided value
to be the given expected
value. The execute
parameter is optional because, by default it takes its value from the global allowIt
parameter specified in the constructor
.
public toBe<Value>(
expectation: string,
value: Value,
expected: any,
execute?: boolean
): this {
this.it(expectation, () => expect(value).toBe(expected), execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
expectation: string | "Textual description of what this spec is checking" with an optional its unique number when adding [counter] . |
value: Value | The value of any type passed to the expect() function of jasmine. |
expected: any | The value of any type passed to the toBe() method of jasmine.Matchers . |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed. By default it takes its value from the global allowIt parameter specified in the constructor . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Object.
import { is } from '@angular-package/type';
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(
true,
false // Execute `it()` method globally is off.
);
/**
* toBe().
*/
testing.describe('string', () => {
testing.toBe(
`Checks the value against the string`,
is.stringType('my name'),
true,
true // Even if globally executing the method `it()` is off, `execute` parameter as `true` executes this spec.
);
});
Testing.prototype.toBeBigInt()
Executes the spec on a state true
from the execute
expecting the provided value
to be a bigint
type on the expected
of true
. The method uses isBigInt()
function of @angular-package/type
.
public toBeBigInt<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be a \`bigint\` type`,
expected: boolean = true
): this {
this.toBe(expectation, is.bigint(value), expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be a bigint type' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Object.
import { is } from '@angular-package/type';
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeBigInt().
*/
testing.describe('bigint', () => testing.toBeBigInt(1n));
Testing.prototype.toBeBooleanType()
Executes the spec on a state true
from the execute
expecting the provided value
to be of a boolean
type on the expected
of true
. The method uses isBooleanType()
function of @angular-package/type
.
public toBeBooleanType<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be of a \`boolean\` type`,
expected: boolean = true
): this {
this.toBe(expectation, is.booleanType(value), expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be of a boolean type' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeBooleanType().
*/
testing.describe('boolean', () => testing.toBeBooleanType(false));
Testing.prototype.toBeClass()
Executes the spec on a state true
from the execute
expecting the provided value
to be a class
on the expected
of true
. The method uses isClass()
function of @angular-package/type
.
public toBeClass<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be a \`class\``,
expected: boolean = true
): this {
this.toBe(expectation, is.class(value), expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be a class' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeClass().
*/
testing.describe('class Person', () => {
class Person {}
testing.toBeClass(Person);
});
Testing.prototype.toBeInstanceOfArray()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of an Array
on the expected
of true
. The method uses isArray()
function of @angular-package/type
.
public toBeInstanceOfArray<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of an \`${Array.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, is.array(value), expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of an Array' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfArray().
*/
testing.describe('Array', () => testing.toBeInstanceOfArray(['1']));
Testing.prototype.toBeInstanceOfBoolean()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of Boolean
on the expected
of true
. The method uses isBooleanObject()
function of @angular-package/type
.
public toBeInstanceOfBoolean<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of \`${Boolean.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, is.booleanObject(value), expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of an Boolean' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfBoolean().
*/
testing.describe('Boolean', () => testing.toBeInstanceOfBoolean(new Boolean()));
Testing.prototype.toBeInstanceOfDate()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of Date
on the expected
of true
. The method uses isDate()
function of @angular-package/type
.
public toBeInstanceOfDate<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of \`${Date.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, is.date(value), expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of Date' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfDate().
*/
testing.describe('Date', () => testing.toBeInstanceOfDate(new Date()));
Testing.prototype.toBeInstanceOfError()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of an Error
the expected
of true
.
public toBeInstanceOfError<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of an \`${Error.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, value instanceof Error, expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of an Error' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfError().
*/
testing.describe('Error', () => {
try {
throw new Error();
} catch (e) {
testing.toBeInstanceOfError(e);
}
});
Testing.prototype.toBeInstanceOfFunction()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of a Function
on the expected
of true
.
public toBeInstanceOfFunction<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of a \`${Function.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, value instanceof Function, expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of a Function' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfFunction().
*/
testing.describe(`Function`, () => testing.toBeInstanceOfFunction(() => {}));
Testing.prototype.toBeInstanceOfMap()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of a Map
on the expected
of true
.
public toBeInstanceOfMap<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of a \`${Map.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, value instanceof Map, expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of a Map' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfMap().
*/
testing.describe(`Map`, () => testing.toBeInstanceOfMap(new Map()));
Testing.prototype.toBeInstanceOfNumber()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of a Number
on the expected
of true
. The method uses isNumberObject()
function of @angular-package/type
.
public toBeInstanceOfNumber<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of a \`${Number.name}\``,
expected: boolean = true,
): this {
this.toBe(expectation, is.numberObject(value), expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of a Number' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* Tests.
*/
testing.describe(`Number`, () =>
testing.toBeInstanceOfNumber(new Number(27))
);
Testing.prototype.toBeInstanceOfObject()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of an Object
on the expected
of true
. The method uses isObject()
function of @angular-package/type
.
public toBeInstanceOfObject<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of an \`${Object.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, is.object(value), expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of an Object' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfObject()
*/
testing.describe(`Object`, () =>
testing
.toBeInstanceOfObject(new Object({}))
.toBeInstanceOfObject({})
);
Testing.prototype.toBeInstanceOfPromise()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of Promise
on the expected
of true
.
public toBeInstanceOfPromise<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of \`${Promise.name}\``,
expected: boolean = true,
): this {
this.toBe(expectation, value instanceof Promise, expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of Promise' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfPromise()
*/
const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('foo');
// reject('foo');
}, 300);
});
testing.describe(`Promise`, () => testing.toBeInstanceOfPromise(myPromise));
Testing.prototype.toBeInstanceOfRangeError()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of RangeError
on the expected
state.
public toBeInstanceOfRangeError<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of \`${RangeError.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, value instanceof RangeError, expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of RangeError' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfRangeError()
*/
testing.describe('RangeError', () => {
try {
throw new RangeError();
} catch (e) {
testing.toBeInstanceOfRangeError(e);
}
});
Testing.prototype.toBeInstanceOfReferenceError()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of ReferenceError
on the expected
of true
.
public toBeInstanceOfReferenceError<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of \`${ReferenceError.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, value instanceof ReferenceError, expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of ReferenceError' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfRangeError()
*/
testing.describe('RangeError', () => {
try {
throw new RangeError();
} catch (e) {
testing.toBeInstanceOfRangeError(e);
}
});
Testing.prototype.toBeInstanceOfRegExp()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of RegExp
on the expected
of true
. The method uses isRegExp()
function of @angular-package/type
.
public toBeInstanceOfRegExp<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of \`${RegExp.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, is.regexp(value), expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of RegExp' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfRegExp()
*/
testing.describe(`RegExp`, () =>
testing.toBeInstanceOfRegExp(new RegExp(/[]/g))
);
Testing.prototype.toBeInstanceOfSet()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of Set
on the expected
of true
.
public toBeInstanceOfSet<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of \`${Set.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, value instanceof Set, expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of Set' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfSet()
*/
testing.describe(`Promise`, () => testing.toBeInstanceOfSet(new Set()));
Testing.prototype.toBeInstanceOfStorage()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of Storage
on the expected
of true
.
public toBeInstanceOfStorage<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of \`${Storage.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, value instanceof Storage, expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of Storage' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfStorage()
*/
testing.describe(`Storage`, () => testing.toBeInstanceOfStorage(window.sessionStorage));
Testing.prototype.toBeInstanceOfString()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of a String
on the expected
of true
. The method uses isStringObject()
function of @angular-package/type
.
public toBeInstanceOfString<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of a \`${String.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, is.stringObject(value), expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of a String' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfString()
*/
testing.describe(`String`, () => testing.toBeInstanceOfString(new String()));
Testing.prototype.toBeInstanceOfSyntaxError()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of SyntaxError
on the expected
of true
.
public toBeInstanceOfSyntaxError<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of \`${SyntaxError.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, value instanceof SyntaxError, expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of SyntaxError' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfSyntaxError()
*/
testing.describe('SyntaxError', () => {
try {
throw new SyntaxError();
} catch (e) {
testing.toBeInstanceOfSyntaxError(e);
}
});
Testing.prototype.toBeInstanceOfTypeError()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of TypeError
on the expected
of true
.
public toBeInstanceOfTypeError<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of \`${TypeError.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, value instanceof TypeError, expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of SyntaxError' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfTypeError()
*/
testing.describe('TypeError', () => {
try {
throw new TypeError();
} catch (e) {
testing.toBeInstanceOfTypeError(e);
}
});
Testing.prototype.toBeInstanceOfURIError()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of URIError
on the expected
of true
.
public toBeInstanceOfURIError<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of \`${URIError.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, value instanceof URIError, expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of URIError' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfURIError()
*/
testing.describe('URIError', () => {
try {
throw new URIError();
} catch (e) {
testing.toBeInstanceOfURIError(e);
}
});
Testing.prototype.toBeInstanceOfWeakSet()
Executes the spec on a state true
from the execute
expecting the provided value
to be an instance of a WeakSet
on the expected
of true
.
public toBeInstanceOfWeakSet<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be an instance of a \`${WeakSet.name}\``,
expected: boolean = true
): this {
this.toBe(expectation, value instanceof WeakSet, expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be an instance of WeakSet' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeInstanceOfWeakSet()
*/
testing.describe(`WeakSet`, () => testing.toBeInstanceOfWeakSet(new WeakSet()));
Testing.prototype.toBeNull()
Executes the spec on a state true
from the execute
expecting the provided value
to be null
on the expected
of true
. The method uses isNull()
function of @angular-package/type
.
public toBeNull<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be \`null\``,
expected: boolean = true
): this {
this.toBe(expectation, is.null(value), expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be null' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeNull()
*/
testing.describe(`null`, () => testing.toBeNull(null));
Testing.prototype.toBeNumberType()
Executes the spec on a state true
from the execute
expecting the provided value
to be of a number
type on the expected
of true
. The method uses isNumberType()
function of @angular-package/type
.
public toBeNull<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be \`null\``,
expected: boolean = true
): this {
this.toBe(expectation, is.null(value), expected, execute);
return this;
}
Parameters:
Name: type | Description |
---|---|
value: Value | The value of any type to check. |
execute?: boolean | An optional parameter that specifies whether the spec is to be executed, by default it takes its value from the global allowIt parameter specified in the constructor . |
expectation: string | The message for the karma, which by default is set to 'The value must be of a number type' . |
expected: boolean | Expects the result of the expectation to be true or false , by default it's true . |
Returns:
The return value is an instance of a Testing
.
Usage:
// Example usage.
// Class.
import { Testing } from '@angular-package/testing';
/**
* Initialize testing.
*/
const testing = new Testing(true, true);
/**
* toBeNumberType()
*/
testing.describe(`number`, () => testing.toBeNumberType(5));
Testing.prototype.toBeStringType()
Executes the spec on a state true
from the execute
expecting the provided value
to be of a string
type on the expected
of true
. The method uses isStringType()
function from the @angular-package/type
.
public toBeStringType<Value>(
value: Value,
execute?: boolean,
expectation: string = `The value must be of a \`string\` type`,
expected: boolean = true
): this {
this.toBe(expect