(will be removed after 1.0.0) Import from https://deno.land/std/assert/mod.ts instead.
A library of assertion functions.
If the assertion is false an AssertionError will be thrown which will
result in pretty-printed diff of failing assertion.
Classes
Error thrown when an assertion fails.
Functions
Make an assertion, error will be thrown if expr does not have truthy value.
Make an assertion that actual and expected are almost equal numbers
through a given tolerance. It can be used to take into account IEEE-754
double-precision floating-point representation limitations. If the values
are not almost equal then throw.
Make an assertion that actual includes the expected values. If not then
an error will be thrown.
Make an assertion that actual and expected are equal, deeply. If not
deeply equal, then throw.
Make an assertion that actual is not null or undefined. If not then throw.
Make an assertion, error will be thrown if expr have truthy value.
Make an assertion that actual is greater than expected.
If not then throw.
Make an assertion that actual is greater than or equal to expected.
If not then throw.
Make an assertion that obj is an instance of type.
If not then throw.
Make an assertion that error is an Error.
If not then an error will be thrown.
An error class and a string that should be included in the
error message can also be asserted.
Make an assertion that actual is less than expected.
If not then throw.
Make an assertion that actual is less than or equal to expected.
If not then throw.
Make an assertion that actual match RegExp expected. If not
then throw.
Make an assertion that actual and expected are not equal, deeply.
If not then throw.
Make an assertion that obj is not an instance of type.
If so, then throw.
Make an assertion that actual not match RegExp expected. If match
then throw.
Make an assertion that actual and expected are not strictly equal.
If the values are strictly equal then throw.
Make an assertion that actual object is a subset of expected object,
deeply. If not, then throw.
Executes a function which returns a promise, expecting it to reject.
Make an assertion that actual and expected are strictly equal. If
not then throw.
Make an assertion that actual includes expected. If not then throw.
Executes a function, expecting it to throw. If it does not, then it throws.
Deep equality comparison used in assertions
Forcefully throws a failed assertion.
Use this to stub out methods that will throw when invoked.
Use this to assert unreachable code.
Type Aliases
Any constructor
An array-like object (Array, Uint8Array, NodeList, etc.) that is not a string.
Assertion condition for assertFalse.
Gets constructor type
A BDD interface
to Deno.test() API.
Functions
Run some shared teardown after all of the tests in the suite.
Run some shared teardown after each test in the suite.
Run some shared setup before all of the tests in the suite.
Run some shared setup before each test in the suite.
Interfaces
Registers a test suite.
The options for creating a test suite with the describe function.
- afterAll:((this: T) => void | Promise<void>)
| ((this: T) => void | Promise<void>)[]Run some shared teardown after all of the tests in the suite.
- afterEach:((this: T) => void | Promise<void>)
| ((this: T) => void | Promise<void>)[]Run some shared teardown after each test in the suite.
- beforeAll:((this: T) => void | Promise<void>)
| ((this: T) => void | Promise<void>)[]Run some shared setup before all of the tests in the suite.
- beforeEach:((this: T) => void | Promise<void>)
| ((this: T) => void | Promise<void>)[]Run some shared setup before each test in the suite.
- fn: () => voidNo documentation available
- suite: TestSuite<T>
The
describefunction returns aTestSuiterepresenting the group of tests. Ifdescribeis called within anotherdescribecallsfn, the suite will default to that parentdescribecalls returnedTestSuite. Ifdescribeis not called within anotherdescribecallsfn, the suite will default to theTestSuiterepresenting the global group of tests.
Registers an individual test case.
The options for creating an individual test case with the it function.
- fn: () => void | Promise<void>this: T,t: Deno.TestContextNo documentation available
- suite: TestSuite<T>
The
describefunction returns aTestSuiterepresenting the group of tests. Ifitis called within adescribecallsfn, the suite will default to that parentdescribecalls returnedTestSuite. Ifitis not called within adescribecallsfn, the suite will default to theTestSuiterepresenting the global group of tests.
Type Aliases
| [string]
| [string, Omit<DescribeDefinition<T>, "name">]
| [string, () => void]
| [() => void]
| [
| [Omit<DescribeDefinition<T>, "fn">, () => void]
| [Omit<DescribeDefinition<T>, "fn" | "name">, () => void]
| [TestSuite<T>, string]
| [
| [TestSuite<T>, string, () => void]
| [TestSuite<T>, () => void]
| [
| [
| [
The arguments for a DescribeFunction.
| [string, Omit<ItDefinition<T>, "name">]
| [
| [(
| [
| [
| [
| [
| [
| [
| [
| [
| [
The arguments for an ItFunction.
A mocking and spying library.
Classes
An error related to spying on a function or instance method.
Functions
Asserts that a spy is called as expected.
Asserts that a spy is called with a specific arg as expected.
Asserts that an spy is called with a specific range of args as expected. If a start and end index is not provided, the expected will be compared against all args. If a start is provided without an end index, the expected will be compared against all args from the start index to the end. The end index is not included in the range of args that are compared.
Asserts that an async spy is called as expected.
Asserts that a spy is called as much as expected and no more.
Creates a session that tracks all mocks created before it's restored. If a callback is provided, it restores all mocks created within it.
Creates an async session that tracks all mocks created before the promise resolves.
| AsyncIterable<Return | Error | Promise<Return | Error>>
Creates a function that resolves the awaited iterable values. Any awaited iterable values that are errors will be thrown.
Restores all mocks registered in the current session that have not already been restored. If an id is provided, it will restore all mocks registered in the session associed with that id that have not already been restored.
Creates a function that returns one of its arguments.
Creates a function that returns its arguments or a subset of them. If end is specified, it will return arguments up to but not including the end.
Creates a function that returns the iterable values. Any iterable values that are errors will be thrown.
Creates a function that returns the instance the method was called on.
| (new (...args: Args) => Self)
| Self,
Wraps a function or instance method with a Spy.
Replaces an instance method with a Stub.
Interfaces
A constructor wrapper that records all calls made to it.
- calls: SpyCall<Self, Args, Self>[]
Information about calls made to the function or instance method.
- new(...args: Args): SelfNo documentation available
- original: new (...args: Args) => Self
The function that is being spied on.
- restore(): void
If spying on an instance method, this restores the original instance method.
- restored: boolean
Whether or not the original instance method has been restored.
Call information recorded by a spy.
- args: [...Args, ...unknown[]]
Arguments passed to a function when called.
- error: { Class?: new (...args: any[]) => Error; msgIncludes?: string; }No documentation available
- returned: Return
The value that was returned by a function. If you expect a promise to reject, expect error instead.
- self: Self
The instance that a method was called on.
A function or instance method wrapper that records all calls made to it.
- calls: SpyCall<Self, Args, Return>[]
Information about calls made to the function or instance method.
- original: () => Returnthis: Self,...args: Args
The function that is being spied on.
- restore(): void
If spying on an instance method, this restores the original instance method.
- restored: boolean
Whether or not the original instance method has been restored.
Call information recorded by a spy.
Type Aliases
A snapshotting library.
Functions
Make an assertion that actual matches a snapshot. If the snapshot and actual do
not a match, then throw.
Default serializer for assertSnapshot.
Type Aliases
Utilities for mocking time while testing.
Classes
Overrides the real Date object and timer functions with fake ones that can be controlled through the fake time instance.
- delay(): Promise<void>ms: number,options?: DelayOptions
Resolves after the given number of milliseconds using real time.
- next(): boolean
Advances time to when the next scheduled timer is due. If there are no pending timers, time will not be changed. Returns true when there is a scheduled timer and false when there is not.
- nextAsync(): Promise<boolean>
Runs all pending microtasks then advances time to when the next scheduled timer is due. If there are no pending timers, time will not be changed.
- now(): number
The amount of milliseconds elapsed since January 1, 1970 00:00:00 UTC for the fake time. When set, it will call any functions waiting to be called between the current and new fake time. If the timer callback throws, time will stop advancing forward beyond that timer.
- restore(): void
Restores real time.
- restoreFor<T>(): Promise<T>callback: (...args: any[]) => Promise<T> | T,...args: any[]
Restores real time temporarily until callback returns and resolves.
- runAll(): void
Advances time forward to the next due timer until there are no pending timers remaining. If the timers create additional timers, they will be run too. If there is an interval, time will keep advancing forward until the interval is cleared.
- runAllAsync(): Promise<void>
Advances time forward to the next due timer until there are no pending timers remaining. If the timers create additional timers, they will be run too. If there is an interval, time will keep advancing forward until the interval is cleared. Runs all pending microtasks before each timer.
- runMicrotasks(): Promise<void>
Runs all pending microtasks.
- start(): number
The initial amount of milliseconds elapsed since January 1, 1970 00:00:00 UTC for the fake time.
- tick(ms?): void
Adds the specified number of milliseconds to the fake time. This will call any functions waiting to be called between the current and new fake time.
- tickAsync(ms?): Promise<void>
Runs all pending microtasks then adds the specified number of milliseconds to the fake time. This will call any functions waiting to be called between the current and new fake time.
An error related to faking time.
Interfaces
- advanceFrequency: number
The frequency in milliseconds at which fake time is updated. If advanceRate is set, we will update the time every 10 milliseconds by default.
- advanceRate: number
The rate relative to real time at which fake time is updated. By default time only moves forward through calling tick or setting now. Set to 1 to have the fake time automatically tick forward at the same rate in milliseconds as real time.
Functions
Asserts at compile time that the provided type argument's type resolves to the expected boolean literal type.
Type Aliases
Asserts at compile time that the provided type argument's type resolves to the expected boolean literal type.
Asserts at compile time that the provided type argument's type resolves to false.
Asserts at compile time that the provided type argument's type resolves to true.
Checks if type T has the specified type U.
Checks if type T is the any type.
Checks if type T exactly matches type U.
Checks if type T is the never type.
Checks if type T is possibly null or undefined.
Checks if type T is the unknown type.
Checks if type T does not have the specified type U.