@types/tap
- Version 15.0.12
- Published
- 34.8 kB
- 1 dependency
- MIT license
Install
npm i @types/tap
yarn add @types/tap
pnpm add @types/tap
Overview
TypeScript definitions for tap
Index
Variables
variable tap
const tap: Tap.Tap;
Namespaces
namespace Assertions
namespace Assertions {}
interface Throws
interface Throws {}
call signature
( fn?: (...args: any[]) => any, expectedError?: any, message?: string, extra?: Options.Assert): boolean;
call signature
( fn?: (...args: any[]) => any, expectedError?: any, extra?: Options.Assert): boolean;
type Basic
type Basic = (obj: any, message?: string, extra?: Options.Assert) => boolean;
type DoesNotThrow
type DoesNotThrow = ( fn?: (...args: any[]) => any, message?: string, extra?: Options.Assert) => boolean;
type Equal
type Equal = ( found: any, wanted: any, message?: string, extra?: Options.Assert) => boolean;
type Match
type Match = ( found: any, pattern: any, message?: string, extra?: Options.Assert) => boolean;
type NotEqual
type NotEqual = ( found: any, notWanted: any, message?: string, extra?: Options.Assert) => boolean;
type Type
type Type = ( found: any, type: string | (new (...args: any[]) => object), message?: string, extra?: Options.Assert) => boolean;
namespace global
namespace global {}
namespace global.Tap
namespace global.Tap {}
class Tap
class Tap extends Test {}
property mocha
mocha: Mocha;
property mochaGlobals
mochaGlobals: () => void;
property Test
Test: TestConstructor;
class Test
class Test extends DeprecatedAssertionSynonyms {}
constructor
constructor(options?: Options.Test);
property cleanSnapshot
cleanSnapshot: (s: string) => string;
Formats a string from a snapshot. This can be used to remove variables and replace them with sentinel values.
Example 1
t.cleanSnapshot = s => { return s.replace(/ time=[0-9]+$/g, ' time={time}') }
See Also
property context
context: any;
This is an object which is inherited by child tests, and is a handy place to put various contextual information.
t.context will only be inherited by child tests if it is an object.
This typically will be used with lifecycle events, such as beforeEach or afterEach.
See Also
property doesNotThrow
doesNotThrow: Assertions.DoesNotThrow;
Verify that the provided function does not throw.
If the function has a name, and the message is not provided, then the function name will be used as the message.
If the function is not provided, then this will be treated as a todo test.
Note: If an error is encountered unexpectedly, it's often better to simply throw it. The Test object will handle this as a failure.
property equal
equal: Assertions.Equal;
Verify that the object found is exactly the same (that is, ===) to the object that is wanted.
property error
error: Assertions.Basic;
If the object is an error, then the assertion fails.
Note: if an error is encountered unexpectedly, it's often better to simply throw it. The Test object will handle this as a failure.
property formatSnapshot
formatSnapshot: (obj: any) => string;
Formats the data argument of any snapshot into this string.
Example 1
t.formatSnapshot = object => JSON.stringify(object)
See Also
property has
has: Assertions.Match;
Verify that the found object contains all of the provided fields, and that they coerce to the same values, even if the types do not match.
This does not do advanced/loose matching based on constructor, regexp patterns, and so on, like t.match() does. You may specify key: undefined in the pattern to ensure that a field is not defined in the found object, but it will not differentiate between a missing property and a property set to undefined.
property hasProp
hasProp: Assertions.Match;
Verify that the found object contains the provided property and that it is not undefined. Searches the prototype chain as well as "own" properties.
Example 1
t.hasProp({ a: 1, b: 2 }, 'a') would succeed, while both t.hasProp({ a: 1, b: 2 }, 'c') and t.hasProp({ a: undefined, b: 2 }, 'a') would fail.
property hasProps
hasProps: Assertions.Match;
Verifies that the object found contains each of the property names in propertyList, and that they are not undefined. Searches prototype chain as well as "own" properties.
Example 1
t.hasProps({ a: 1, b: 2 }, ['a', 'b']) would succeed, while both t.hasProp({ a: 1, b: 2 }, ['a', 'c']) and t.hasProp({ a: undefined, b: 2 }, ['a', 'b']) would fail.
property hasStrict
hasStrict: Assertions.Match;
Verify that the found object contains all of the provided fields, and that they are of the same type and value as the pattern provided.
See Also
has
property jobs
jobs: number;
If you set the t.jobs property to a number greater than 1, then it will enable parallel execution of all of this test's children.
property match
match: Assertions.Match;
Verify that the found object matches the pattern provided.
If pattern is a regular expression, and found is a string, then verify that the string matches the pattern. If the pattern is a string, and found is a string, then verify that the pattern occurs within the string somewhere. If pattern is an object, then verify that all of the (enumerable) fields in the pattern match the corresponding fields in the object using this same algorithm.
This is useful when you want to verify that an object has a certain set of required fields, but additional fields are ok.
Example 1
{x:/a[sdf]{3}/} would successfully match {x:'asdf',y:'z'}.
property name
readonly name: string;
This is a read-only property set to the string value provided as the name argument to t.test(), or an empty string if no name is provided.
property not
not: Assertions.NotEqual;
Inverse of t.equal().
Verify that the object found is not exactly the same (that is, !==) as the object that is wanted.
property notMatch
notMatch: Assertions.Match;
Inverse of match().
Verify that the found object does not match the pattern provided.
property notOk
notOk: Assertions.Basic;
Verifies that the object is not truthy.
property notSame
notSame: Assertions.NotEqual;
Inverse of t.same().
Verify that the found object is not deeply equivalent to the unwanted object. Uses non-strict inequality (ie, !=) for scalars.
property ok
ok: Assertions.Basic;
Verifies that the object is truthy.
property runOnly
runOnly: boolean;
Set to true to only run child tests that have only: true set in their options (or are run with t.only(), which is the same thing).
property same
same: Assertions.Equal;
Verify that the found object is deeply equivalent to the wanted object.
Uses non-strict equality for scalars (ie, ==).
property strictNotSame
strictNotSame: Assertions.NotEqual;
Inverse of t.strictSame().
Verify that the found object is not deeply equivalent to the unwanted object. Uses strict equality for scalars (ie, ===).
property strictSame
strictSame: Assertions.Equal;
Strict version of t.same().
Verify that the found object is deeply equivalent to the wanted object. Uses strict equality for scalars (ie, ===).
property testdirName
readonly testdirName: string;
property throws
throws: Assertions.Throws;
Expect the function to throw an error. If an expected error is provided, then also verify that the thrown error matches the expected error.
If the function has a name, and the message is not provided, then the function name will be used as the message.
If the function is not provided, then this will be treated as a todo test.
property type
type: Assertions.Type;
Verify that the object is of the type provided.
Type can be a string that matches the typeof value of the object, or the string name of any constructor in the object's prototype chain, or a constructor function in the object's prototype chain.
Example 1
type(new Date(), "object") - true
Example 2
type(new Date(), "Date") - true
Example 3
type(new Date(), Date) - true
method addAssert
addAssert: ( name: string, length: number, fn: (...args: any[]) => boolean) => boolean;
This is used for creating assertion methods on the Test class.
Parameter name
The name of the assertion method.
Parameter length
The amount of arguments the assertion has.
Parameter fn
The code to be ran when this assertion is called.
Example 1
// Add an assertion that a string is in Title Case // It takes one argument (the string to be tested) t.Test.prototype.addAssert('titleCase', 1, function (str, message, extra) { message = message || 'should be in Title Case' // the string in Title Case const tc = str.toLowerCase().replace(/\b./, match => match.toUpperCase()) // should always return another assert call, or // this.pass(message) or this.fail(message, extra) return this.equal(str, tc, message, extra) })
t.titleCase('This Passes') t.titleCase('however, tHis tOTaLLy faILS')
method afterEach
afterEach: (fn: (() => any) | ((childTest: any) => any)) => void;
This is called after each child test (or any children of any child tests, on down the tree). Like beforeEach, it's called with the child test object, and can return a Promise to perform asynchronous operations.
method autoend
autoend: (value: boolean) => void;
Automatically end() the test on the next turn of the event loop after its internal queue is drained.
method bailout
bailout: (reason?: string) => void;
Use this when things are severely broken, and cannot be reasonably handled. Immediately terminates the entire test run.
method before
before: (fn: () => any) => void;
Run the provided function once before any tests are ran. If this function returns a promise, it will wait for the promise to resolve, before running any tests.
method beforeEach
beforeEach: (fn: (() => any) | ((childTest: any) => any)) => void;
Before any child test (or any children of any child tests, etc.) the supplied function is called with the test object that it's prefixing.
If the function returns a Promise, then that is used as the indication of doneness. Thus, async functions automatically end when all of their awaited Promises are complete.
method comment
comment: (message: string, ...args: any[]) => void;
method current
current: () => Test;
method done
done: () => void;
method emits
emits: ( eventEmitter: EventEmitter, event: string, message?: string, extra?: Options.Assert) => void;
Verify that the event emitter emits the named event before the end of the test.
method end
end: () => void;
Call when tests are done running. This is not necessary if t.plan() was used, or if the test function returns a Promise.
If you call t.end() explicitly more than once, an error will be raised.
method endAll
endAll: () => void;
Call the end() method on all child tests, and then on this one.
method expectUncaughtException
expectUncaughtException: ( fn?: (...args: any[]) => any, expectedError?: Error, message?: string, extra?: Options.Assert) => boolean;
Expect the function to throw an uncaught exception at some point in the future, before the test ends. If the test ends without having thrown the expected error, then the test fails.
If the error is thrown synchronously, or within a promise, then the t.throws() or t.rejects() methods are more appropriate.
If called multiple times, then the uncaught exception errors must be emitted in the order called.
method fail
fail: (message?: string, extra?: Options.Assert) => boolean;
method fixture
fixture: { (type: 'symlink' | 'link', content: string): Fixture.Instance; (type: 'file', content: any): Fixture.Instance; (type: 'dir', content: Fixture.Spec): Fixture.Instance;};
Create a fixture object to specify hard links and symbolic links in the fixture definition object passed to t.testdir().
method matchSnapshot
matchSnapshot: ( output: any, message?: string, extra?: Options.Assert) => boolean;
Checks if the output in data matches the data with this snapshot name.
See Also
method mock
mock: (modulePath: string, mocks: Record<string, any>) => any;
Takes a path to a module and returns the specified module in context of the mocks provided.
Parameter modulePath
The string path to the module that is being required, relative to the current test file.
Parameter mocks
The key/value pairs of paths (relative to the current test) and the value that should be returned when anything in the loaded module requires those modules.
See Also
method only
only: { (name: string, cb?: (t: Test) => Promise<void> | void): Promise<void>; ( name: string, extra?: Options.Test, cb?: (t: Test) => void | Promise<void> ): Promise<void>;};
Exactly the same as t.test(), but adds only: true in the options.
See Also
method pass
pass: (message?: string, extra?: Options.Assert) => boolean;
method passing
passing: () => boolean;
Return true if everything so far is ok.
method plan
plan: (n: number, comment?: string) => void;
Specify that a given number of tests are going to be run.
This may only be called before running any asserts or child tests.
method pragma
pragma: (set: Options.Pragma) => void;
Sets a pragma switch for a set of boolean keys in the argument.
The only pragma currently supported by the TAP parser is strict, which tells the parser to treat non-TAP output as a failure.
method rejects
rejects: { ( promiseOrFn: Promise<any> | ((...args: any[]) => Promise<any>), expectedError: any, message?: string, extra?: Options.Assert ): Promise<void>; ( promiseOrFn: Promise<any> | ((...args: any[]) => Promise<any>), message?: string, extra?: Options.Assert ): Promise<void>;};
Verifies that the promise (or promise-returning function) rejects.
If an expected error is provided, then also verify that the rejection matches the expected error.
method resolveMatch
resolveMatch: ( promiseOrFn: Promise<any> | ((...args: any[]) => Promise<any>), wanted: any, message?: string, extra?: Options.Assert) => Promise<void>;
Verifies that the promise (or promise-returning function) resolves and that the value of the promise matches the wanted pattern using t.match.
See Also
match
method resolveMatchSnapshot
resolveMatchSnapshot: ( promiseOrFn: Promise<any> | ((...args: any[]) => Promise<any>), message?: string, extra?: Options.Assert) => Promise<void>;
Verifies that the promise (or promise-returning function) resolves, and furthermore that the value of the promise matches the snapshot.
Note: since promises always reject and resolve asynchronously, this assertion is implemented asynchronously. As such, it does not return a boolean to indicate its passing status. Instead, it returns a Promise that resolves when it is completed.
method resolves
resolves: ( promiseOrFn: Promise<any> | ((...args: any[]) => Promise<any>), message?: string, extra?: Options.Assert) => Promise<void>;
Verifies that the promise (or promise-returning function) resolves, making no expectation about the value that the promise resolves to.
method setTimeout
setTimeout: (n: number) => void;
Fail the test with a timeout error if it goes longer than the specified number of ms.
Call t.setTimeout(0) to remove the timeout setting.
When this is called on the top-level tap object, it sets the runners timeout value to the specified value for that test process as well.
method skip
skip: { (name: string, cb?: (t: Test) => Promise<void> | void): Promise<void>; ( name: string, extra?: Options.Test, cb?: (t: Test) => void | Promise<void> ): Promise<void>;};
Exactly the same as t.test(), but adds skip: true in the options.
method spawn
spawn: ( cmd: string, args: string, options?: Options.Bag, name?: string, extra?: Options.Spawn) => Promise<void>;
Sometimes, instead of running a child test directly inline, you might want to run a TAP producting test as a child process, and treat its standard output as the TAP stream.
Returns a Promise which resolves with the parent when the child process is completed.
See Also
method stdin
stdin: (name: string, extra?: Options.Bag) => Promise<void>;
Parse standard input as if it was a child test named /dev/stdin.
Returns a Promise which resolves with the parent when the input stream is completed.
method teardown
teardown: (fn: () => void | Promise<void>) => void;
Run the supplied function when t.end() is called, or when t.plan is met.
This function can return a promise to support async actions.
Parameter fn
See Also
method test
test: { ( name: string, extra?: Options.Test, cb?: (t: Test) => Promise<void> | void ): Promise<void>; (name: string, cb?: (t: Test) => void | Promise<void>): Promise<void>;};
Create a subtest.
Returns a Promise which resolves with the parent when the child test is completed.
Parameter name
The name for this subtest.
Parameter extra
Any options this subtest should adhere to.
Parameter cb
The function containing the sub-tests. If not present, the test will automatically be marked as a todo.
Create a subtest.
Returns a Promise which resolves with the parent when the child test is completed.
Parameter name
The name for this subtest.
Parameter cb
The function containing the sub-tests. If not present, the test will automatically be marked as a todo.
method testdir
testdir: (spec?: Fixture.Spec) => string;
Create a fresh directory with the specified fixtures, which is deleted on test teardown. Returns the directory name.
See Also
method threw
threw: (error: Error, extra?: Error, proxy?: Test) => void;
When an uncaught exception is raised in the context of a test, then this method is used to handle the error. It fails the test, and prints out appropriate information about the stack, message, current test, and so on.
Generally, you never need to worry about this directly.
method todo
todo: { (name: string, cb?: (t: Test) => Promise<void> | void): Promise<void>; ( name: string, extra?: Options.Test, cb?: (t: Test) => void | Promise<void> ): Promise<void>;};
Exactly the same as t.test(), but adds todo: true in the options.
interface Mocha
interface Mocha {}
interface MochaIt
interface MochaIt {}
property skip
skip: (name?: string, fn?: (a: any) => any) => void;
property todo
todo: (name?: string, fn?: (a: any) => any) => void;
call signature
(name?: string, fn?: (a: any) => any): void;
interface TestConstructor
interface TestConstructor {}
property prototype
prototype: Test;
construct signature
new (options?: Options.Test): Test;
namespace global.Tap.Fixture
namespace global.Tap.Fixture {}
interface Instance
interface Instance {}
interface Spec
interface Spec {}
index signature
[pathname: string]: string | Buffer | Instance | Spec;
namespace Options
namespace Options {}
interface Assert
interface Assert extends Bag {}
property diagnostic
diagnostic?: boolean | undefined;
property skip
skip?: boolean | string | undefined;
property todo
todo?: boolean | string | undefined;
interface Bag
interface Bag {}
index signature
[key: string]: any;
interface Pragma
interface Pragma {}
index signature
[key: string]: boolean;
interface Spawn
interface Spawn extends Assert {}
interface Test
interface Test extends Assert {}
property autoend
autoend?: boolean | undefined;
property bail
bail?: boolean | undefined;
property buffered
buffered?: boolean | undefined;
property grep
grep?: RegExp[] | undefined;
property jobs
jobs?: number | undefined;
property only
only?: boolean | undefined;
property runOnly
runOnly?: boolean | undefined;
property timeout
timeout?: number | undefined;
Package Files (1)
Dependencies (1)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@types/tap
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@types/tap)
- HTML<a href="https://www.jsdocs.io/package/@types/tap"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 5150 ms. - Missing or incorrect documentation? Open an issue for this package.