Returns expectation with the opposite meaning. For example:
t.expect(1).toBe(1)
t.expect(1).not.toBe(2)
This method applies its 1st argument (if any) to the current instance using Object.assign()
.
Supposed to be overridden in the subclasses to customize the instance creation process.
An expected value
This assertion passes, when the number provided to the expect method is approximately equal
the given number. The proximity can be defined as the precision
argument
The number to compare with
The number approximation
This assertion passes, when value provided to the expect method is not the undefined
value.
An alias for toEqual
This assertion passes, when value provided to the expect method is "falsy" - evaluates to false
.
For example - empty strings, number 0, null
, undefined
, etc.
This assertion passes, when the number provided to the expect method is greater or equal than the expected number.
The number to compare with
This assertion passes, when the number provided to the expect method is greater than the expected number.
The number to compare with
This assertion passes, when the number provided to the expect method is less or equal than the expected number.
The number to compare with
This assertion passes, when the number provided to the expect method is less than the expected number.
The number to compare with
This assertion passes, when value provided to the expect method is NaN
.
This assertion passes, when value provided to the expect method is null
.
This assertion passes, when value provided to the expect method is "truthy" - evaluates to true
.
For example - non empty strings, numbers except the 0, objects, arrays etc.
This assertion passes, when value provided to the expect method is the undefined
value.
This assertion passes in 2 cases:
The element of the array or a sub-string
This assertion compares the value provided to the expect method with the expectedValue
argument.
Comparison works for objects, arrays, and JSON in general. It is performed "deeply". Cyclic structures are properly handled.
This method works correctly with the fuzzy matchers generated with the any method
An expected value
This assertion passes, if a spy, provided to the expect method have been called expected number of times. The expected number of times can be provided as the 1st argument and by default is 1.
One can also provide the function, spied on, to the expect method.
Examples:
const spy = t.spyOn(obj, 'process')
// call the method 2 times
obj.process()
obj.process()
// following 2 calls are equivalent
t.expect(spy).toHaveBeenCalled();
t.expect(obj.process).toHaveBeenCalled();
// one can also use exact number of calls or comparison operators
t.expect(spy).toHaveBeenCalled(2);
t.expect(spy).toHaveBeenCalled('>1');
t.expect(spy).toHaveBeenCalled('<=3');
See also toHaveBeenCalledWith
Expected number of calls. Can be either a number, specifying the exact number of calls, or a string. In the latter case one should include a comparison operator in front of the number.
This assertion passes, if a spy, provided to the expect method have been called at least once with the specified arguments.
One can also provide the function, spied on, to the expect method.
One can use fuzzy matchers, generated with the any method to verify the arguments.
Example:
const spy = t.spyOn(obj, 'process')
// call the method 2 times with different arguments
obj.build('development', '1.0.0')
obj.build('release', '1.0.1')
t.expect(spy).toHaveBeenCalledWith('development', '1.0.0');
// or
t.expect(obj.process).toHaveBeenCalledWith('development', t.any(String));
See also toHaveBeenCalled
This assertion passes, when the string provided to the expect method matches the regular expression.
The regular expression to match the string against
This assertion passes when the function provided to the expect method, throws an exception during its execution.
t.expect(function(){
throw "oopsie";
}).toThrow());
This is a type-safe static constructor method, accepting a single argument. If that argument is already an instance of this class - it is returned right away, otherwise the new constructor is used for instantiation.
This is a type-safe static constructor method, accepting a single argument, with the object, corresponding to the class properties. It will generate a compilation error, if unknown property is provided.
For example:
class MyClass extends Base {
prop : string
}
const instance : MyClass = MyClass.new({ prop : 'prop', wrong : 11 })
will produce:
TS2345: Argument of type '{ prop: string; wrong: number; }' is not assignable to parameter of type 'Partial<MyClass>'.
Object literal may only specify known properties, and 'wrong' does not exist in type 'Partial<MyClass>'
The only thing this constructor does is create an instance and call the initialize method on it, forwarding the first argument. The customization of instance is supposed to be performed in that method.
Generated using TypeDoc
This class is the central point for writing assertions in the BDD style. Instances of this class can be generated with the expect method.
Then, a call of some method on the expectation instance will create a new assertion in the test.
To negate any assertion, you can use a special property not, that contains another expectation instance with the opposite meaning.
For example: