Options
All
  • Public
  • Public/Protected
  • All
Menu

Test class for code running in the browser environment.

Please refer to the TestDescriptorBrowser documentation for the list of available config options.

Hierarchy

  • TestBrowser<this>
    • TestBrowser

Index

Assertion modifiers

not

  • get not(): this
  • This is an assertion modifier. It returns the test instance itself, but the next added assertion is specialized in a certain way.

    This modifier "inverts" the assertion, so it obtains a negative semantic.

    For example, there's a equal assertion which passes, when provided objects are the structurally the same. Inverted assertion will pass when provided objects are structurally different:

    t.equal(1, 1) // passes
    t.not.equal(1, 2) // passes
    t.not.equal(1, 1) // fails

    Any assertion can be negated in this way, except the ones related to waiting, like waitFor.

    category

    Assertion modifiers

    Returns this

silent

  • get silent(): this
  • This is an assertion modifier. It returns the test instance itself, but the next added assertion is specialized in a certain way.

    This modifier makes the assertion "silent" - it will only appear in the test log if it fails.

    Note, that by default, the console output already hides passed assertions. The dashboard interface however shows them.

    This modifier causes the passed assertion to be physically excluded from the log, so it won't appear in any kind of user interface or report.

    For example:

    t.silent.equal(1, 1) // passes, assertion excluded from the log
    t.silent.equal(1, 2) // fails, assertion will be included in the log as usual

    Any assertion can be modified in this way.

    category

    Assertion modifiers

    Returns this

expect

  • This method returns an "expectation" instance, which can be used to check various assertions about the passed value.

    Every expectation has a special property not, that contains another expectation, but with the negated meaning.

    For example:

    t.expect(1).toBe(1)
    t.expect(1).not.toBe(2)

    t.expect('Foo').toContain('oo')
    t.expect('Foo').not.toContain('bar')

    Please refer to the documentation of the Expectation class for the list of available methods.

    Parameters

    • received: unknown

    Returns Expectation

Asynchronicity

beginAsync

  • beginAsync(timeout?: number): number
  • Normally, to test the asynchronous code, you just make your test function async and await on any asynchronous method call inside of it:

    import { it } from "@bryntum/siesta/index.js"
    import { MyClass } from "my-lib"

    it('Testing asynchronous code should work', async t => {
    const myClass = new MyClass()

    await myClass.asyncMethod('do something')
    })

    However, for example if code is using callbacks, you might not have a Promise instance to await for.

    In such case, use this method to indicate the beginning of the "asynchronous gap" in the code flow. Each gap should be finalized with the endAsync call within the timeout milliseconds, otherwise a failed assertion will be reported.

    The test will wait for all asynchronous gaps to complete before it will finalize.

    For example:

    import { it } from "@bryntum/siesta/index.js"
    import { MyClass } from "my-lib"

    it('Testing asynchronous code should work', t => {
    const myClass = new MyClass()

    // indicate async gap starts
    const async = t.beginAsync()

    myClass.asyncMethodWithCallback(() => {
    // indicate async gap completes
    t.endAsync(async)
    })
    })

    Parameters

    • timeout: number = ...

    Returns number

    The "gap id" opaque object, which should be passed to the endAsync call.

endAsync

  • endAsync(gapId: number): void
  • This method finalizes the "asynchronous gap" started with beginAsync.

    Parameters

    • gapId: number

      The gap id to finalize (returned by the beginAsync method)

    Returns void

waitFor

  • waitFor<R>(waiting: number, description?: string): Promise<R>
  • waitFor<R>(waiting: () => OrPromise<R>, description?: string): Promise<R>
  • waitFor<R>(waiting: Partial<WaitForOptions<R>>): Promise<R>
  • This assertion passes, if waiting for some condition has completed successfully, within the expected timeout.

    The condition to wait for should be specified as a checker function. It can be async if needed (return a Promise). For the waiting to complete, the condition checker should return some "truthy" value, like true, 1, 'some_string', etc. That value (wrapped in a Promise) will be returned from the waitFor method itself.

    Alternatively, this method can just await for certain time.

    This method has 3 overloads:

    • one for waiting the specified time
    • one when checker function is provided directly in the argument
    • one with options argument. In this overload, all options are available, for example, one can customize the maximum time to wait - timeout.

    Note, this method is async. Don't forget to await on it. .

    For example:

    await t.waitFor(() => /Special/.test(document.title))

    await t.waitFor({
    condition : () => document.readyState === 'complete'),
    timeout : 30000,
    interval : 1000
    })

    const elements = await t.waitFor(() => {
    const els = document.querySelectorAll('.some_class')

    return els.length > 0 ? els : null
    })

    IMPORTANT: To avoid race conditions, always start waiting for certain event, before triggering it. See the trigger option in the WaitForOptions object for more details.

    Type parameters

    • R

    Parameters

    • waiting: number
    • Optional description: string

    Returns Promise<R>

  • Type parameters

    • R

    Parameters

    • waiting: () => OrPromise<R>
        • (): OrPromise<R>
        • Returns OrPromise<R>

    • Optional description: string

    Returns Promise<R>

  • Type parameters

    • R

    Parameters

    Returns Promise<R>

Boolean comparison

false

  • false<V>(value: V, description?: string): void
  • This assertion passes if provided value is "falsy" - false, 0, '' etc.

    Type parameters

    • V

    Parameters

    • value: V
    • description: string = ''

    Returns void

notOk

  • notOk<V>(value: V, description?: string): void
  • Backward compatibility alias for false

    Type parameters

    • V

    Parameters

    • value: V
    • description: string = ''

    Returns void

ok

  • ok<V>(value: V, description?: string): void
  • Backward compatibility alias for true

    Type parameters

    • V

    Parameters

    • value: V
    • description: string = ''

    Returns void

true

  • true<V>(value: V, description?: string): void
  • This assertion passes if provided value is "truthy" - true, 1, 'non_empty_string' etc

    Type parameters

    • V

    Parameters

    • value: V
    • description: string = ''

    Returns void

Dom assertions

elementPointIsReachable

  • This assertion passes if the given offset point of the target element is directly reachable by the user, i.e. it is not covered with some other element. If the offset is not provided, the center of the element is tested. The test is performed using the document.getElementFromPoint() method.

    Usually it is fine if the element is covered with one of its children - it is still considered reachable. This behaviour is controlled with the allowChildren option, by default it is set to true.

    This method has 2 overloads, one simplified and one with options.

    Parameters

    Returns any

  • Parameters

    Returns any

elementValueIs

  • elementValueIs(target: ActionTarget, value: string, description?: string): void
  • This assertion passes, if the value property of the target element is strictly equal to the given value argument. No assumption is made about what is the target element, but usually it should be <input> or <textarea>.

    For example:

    t.elementValuesIs('#input1', 'Need this text', 'Correct text in the input field')
    

    Parameters

    • target: ActionTarget
    • value: string
    • Optional description: string

    Returns void

selectorExists

  • selectorExists(selector: string, description?: string): void
  • This assertion passes if the given CSS / ActionTarget selector is found in the DOM.

    Parameters

    • selector: string

      A CSS or ActionTarget selector

    • Optional description: string

      The description for the assertion

    Returns void

waitForSelector

  • waitForSelector(selector: string, root: ActionTarget): any
  • waitForSelector(selector: string, options?: { root?: ActionTarget; timeout?: number }): any
  • This assertions passes if waiting for the given selector completes within timeout. If no timeout is given TestDescriptor.defaultTimeout is used. One can also specify a root element, from which the query will be starting.

    This method has 2 overloads

    For example:

    await t.waitForSelector('.css-class', { root : '.root', timeout : 5000 })
    

    Parameters

    Returns any

  • Parameters

    • selector: string
    • Optional options: { root?: ActionTarget; timeout?: number }
      • Optional root?: ActionTarget

        include

      • Optional timeout?: number

        include

    Returns any

waitForSelectors

  • waitForSelectors(selector: string[], root: ActionTarget): any
  • waitForSelectors(selector: string[], options?: { root?: ActionTarget; timeout?: number }): any
  • This assertions passes if waiting for the given selector completes within timeout. If no timeout is given TestDescriptor.defaultTimeout is used. One can also specify a root element, from which the query will be starting.

    This method has 2 overloads

    For example:

    await t.waitForSelector('.css-class', { root : '.root', timeout : 5000 })
    

    Parameters

    Returns any

  • Parameters

    • selector: string[]
    • Optional options: { root?: ActionTarget; timeout?: number }
      • Optional root?: ActionTarget

        include

      • Optional timeout?: number

        include

    Returns any

Dom helper methods

$

  • $(query: string, root?: Element | Document): Element
  • Performs a query in the DOM using query method and returns the 1st element from the results.

    Parameters

    • query: string
    • root: Element | Document = ...

    Returns Element

$$

  • $$(query: string, root?: Element | Document): Element[]
  • Synonym for query.

    Parameters

    • query: string
    • root: Element | Document = ...

    Returns Element[]

getCaretPosition

  • This helper method returns an index of the caret position (0-based) in the given target element

    Parameters

    Returns number

getSelectedText

  • This helper method returns a selected text in the given target element

    Parameters

    Returns string

moveCaretPosition

  • moveCaretPosition(target: ActionTarget, delta: number): void
  • This helper method moves the caret position in the given target element by the delta.

    Parameters

    Returns void

query

  • query(query: string, root?: Element | Document | ShadowRoot): Element[]
  • Performs a query in the DOM, by default it is a regular CSS query with extra capabilities.

    Notably, the :contains(text) pseudo is supported. It matches, if the text content of the element contains the provided text.

    Also, the -> characters split the query into segments, and each segment matches inside a "context". Context can be either an iframe or a web component shadow DOM. Simply put, the -> symbol marks the boundary of the iframe/web component. Web component need to have "opened" shadow DOM for query to work.

    For example:

    // matches the `body` element of all iframes with `my-frame` CSS class
    .my-frame -> body

    // matches the `body` element of all iframes with `nested-frame` CSS class, which are in turn contained
    // inside the iframes with `my-frame` class
    .my-frame -> .nested-frame -> body

    // matches the elements with `target-class` CSS class, which are inside the shadow DOM of the
    // web component element with `my-web-comp1` class
    .my-web-comp1 -> .target-class

    This method uses querySingleContext to perform simple query inside a single context.

    Parameters

    • query: string

      An enhanced CSS selector

    • root: Element | Document | ShadowRoot = ...

      The root DOM element (or a Document) from which to start the query. Optional, by default its the document of the test context.

    Returns Element[]

querySingleContext

  • querySingleContext(query: string, root?: Element | Document | ShadowRoot): Element[]
  • You probably don't need to use this method in your tests. Use query instead. This method can be overridden by the subclass, to provide some extra query syntax, features etc.

    Performs a query in the DOM, by default it is a regular CSS query. Query is performed inside a single DOM context (single iframe or single web component). See query for cross-context querying capabilities.

    Parameters

    • query: string
    • root: Element | Document | ShadowRoot = ...

    Returns Element[]

selectText

  • selectText(target: ActionTarget, start?: number, end?: number): void
  • This helper method selects text in the given target element, starting from the index start (0-based) till the index end

    Parameters

    • target: ActionTarget
    • Optional start: number
    • Optional end: number

    Returns void

setCaretPosition

  • setCaretPosition(target: ActionTarget, caretPos: number): void
  • This helper method sets the index of the caret position (0-based) in the given target element.

    Parameters

    Returns void

Equality

eq

  • eq<V>(received: V, expected: V, description?: string): void
  • A shorter alias for equal

    Type parameters

    • V

    Parameters

    • received: V
    • expected: V
    • description: string = ''

    Returns void

equal

  • equal<V>(received: V, expected: V, description?: string): void
  • This assertion passes if the received (left) and expected (right) values are "structurally" equal, the so called "deep" equality.

    Map, Set and other native JavaScript data types are supported. Currently these objects are compared by their content, any extra properties, set on them, will not be compared. We plan to support this use case if there will be a demand for it.

    Cyclic data structures are supported. Fuzzy matchers, like any, anyNumberApprox, etc are supported inside the expected data.

    Type parameters

    • V

    Parameters

    • received: V
    • expected: V
    • description: string = ''

    Returns void

equalDeep

  • equalDeep<V>(received: V, expected: V, description?: string): void
  • This assertion passes if the received (left) and expected (right) values are "structurally" equal, the so called "deep" equality.

    Map, Set and other native JavaScript data types are supported. Currently these objects are compared by their content, any extra properties, set on them, will not be compared. We plan to support this use case if there will be a demand for it.

    Cyclic data structures are supported. Fuzzy matchers, like any, anyNumberApprox, etc are supported inside the expected data.

    Type parameters

    • V

    Parameters

    • received: V
    • expected: V
    • description: string = ''

    Returns void

is

  • is<V>(received: V, expected: V, description?: string): void
  • This is Siesta 5 backward compatible assertion, which performs comparison of the 2 values, using the == comparison. So, null will be equal to undefined, 4 to "4" and so on. As an additional quirk, Date instances are compared structurally, by their time, instead of by reference.

    The fuzzy matchers, like any, anyNumberApprox, etc are supported for the expected value.

    It is recommended to use the deep structural equality instead of this assertion, check equal and its shortcut alias eq.

    Type parameters

    • V

    Parameters

    • received: V
    • expected: V
    • description: string = ''

    Returns void

isDeeply

  • isDeeply<V>(value1: V, value2: V, description?: string): void
  • Backward compatible alias for equal

    Type parameters

    • V

    Parameters

    • value1: V
    • value2: V
    • description: string = ''

    Returns void

isNot

  • isNot<V>(value1: V, value2: V, description?: string): void
  • The negated version of is. Can be also written as t.not.is(). See t.not for details.

    Type parameters

    • V

    Parameters

    • value1: V
    • value2: V
    • description: string = ''

    Returns void

isStrict

  • isStrict<V>(value1: V, value2: V, description?: string): void
  • This assertion passes if the received and expected values are equal, as defined by the === operator.

    Type parameters

    • V

    Parameters

    • value1: V
    • value2: V
    • description: string = ''

    Returns void

ne

  • ne<V>(value1: V, value2: V, description?: string): void
  • A shorter alias for notEqual. Can be also written as t.not.eq(), see t.not for details.

    Type parameters

    • V

    Parameters

    • value1: V
    • value2: V
    • description: string = ''

    Returns void

notEqual

  • notEqual<V>(value1: V, value2: V, description?: string): void
  • This assertion passes if the received (left) and expected (right) values are "structurally" not equal, the so called "deep" inequality.

    See equal for details.

    Type parameters

    • V

    Parameters

    • value1: V
    • value2: V
    • description: string = ''

    Returns void

Exceptions handling

doesNotThrow

  • doesNotThrow(func: AnyFunction<any>, description?: string): Promise<void>
  • This assertion passes, if the provided function func does not throw any exceptions.

    import { it } from "@bryntum/siesta/index.js"

    it('Test section', async t => {
    t.doesNotThrow(() => {}, 'No exceptions thrown')
    })

    The func function may be async or return Promise. In such case, do not forget to await on the assertion method itself:

    import { it } from "@bryntum/siesta/index.js"

    it('Test section', async t => {
    await t.doesNotThrow(async () => {}, 'No exceptions thrown')
    })

    See also throws

    Parameters

    Returns Promise<void>

livesOk

  • livesOk(func: AnyFunction<any>, description?: string): Promise<void>
  • Backward compatible alias for doesNotThrow

    Parameters

    Returns Promise<void>

throws

  • throws(func: AnyFunction<any>, pattern?: string | RegExp, description?: string): Promise<void>
  • This assertion passes, if the provided function func throws an exception, which stringifies to the pattern.

    import { it } from "@bryntum/siesta/index.js"

    it('Test section', async t => {
    t.throws(() => throw new Error("oops"), /oop/i, 'Correct exception thrown')
    })

    The func function may be async or return Promise. In such case, do not forget to await on the assertion method itself:

    import { it } from "@bryntum/siesta/index.js"

    it('Test section', async t => {
    await t.throws(async () => throw new Error("oops"), /oop/i, 'Correct exception thrown')
    })

    See also doesNotThrow

    Parameters

    • func: AnyFunction<any>

      The function to call. May be async or return Promise. In such case, do not forget to await on the assertion method itself:

    • pattern: string | RegExp = ''
    • description: string = ''

    Returns Promise<void>

throwsOk

  • throwsOk(func: AnyFunction<any>, pattern: string | RegExp, description?: string): Promise<void>
  • Backward compatible alias for throws

    Parameters

    • func: AnyFunction<any>
    • pattern: string | RegExp
    • description: string = ''

    Returns Promise<void>

Function calls assertions

isCalled

  • isCalled<T, K>(property: AnyFunction<any> | K, object: T, desc?: string): void
  • This is a shortcut alias for isCalledNTimes, with the expected argument hardcoded to the >= 1. It passes if the function property is called at least one time during the test life span.

    Type parameters

    • T: object

    • K: string | number | symbol

    Parameters

    • property: AnyFunction<any> | K

      The function itself or the name of the function property on the host object (2nd argument)

    • object: T

      The host object

    • Optional desc: string

      The description of the assertion

    Returns void

isCalledNTimes

  • isCalledNTimes<T, K>(property: AnyFunction<any> | K, object: T, expected: string | number, desc?: string, isGreaterEqual?: boolean): void
  • This assertion passes if the object's function property is called the expected number of times during the test life span. The expected number of calls can be either a number or a string, consisting from the comparison operator and a number. See [[FiresOkOptions.events]] for more details.

    For example:

    const obj = {
    data : 1,
    increment : function () {
    return ++this.data
    }
    }

    // exact number of calls
    t.isCalledNTimes('increment', obj, 3, 'Correct number of calls to `increment`')

    // expected number of calls as expression
    t.isCalledNTimes('increment', obj, '<= 3', 'Correct number of calls to `increment`')

    // passing property itself
    t.isCalledNTimes(obj.increment, obj, 3, 'Correct number of calls to `increment`')

    Type parameters

    • T: object

    • K: string | number | symbol

    Parameters

    • property: AnyFunction<any> | K

      The function itself or the name of the function property on the host object (2nd argument)

    • object: T

      The host object

    • expected: string | number

      The expected number of calls

    • Optional desc: string

      The description of the assertion

    • Optional isGreaterEqual: boolean

    Returns void

isCalledOnce

  • isCalledOnce<T, K>(property: AnyFunction<any> | K, object: T, desc?: string): void
  • This is a shortcut alias for isCalledNTimes, with the expected argument hardcoded to the 1. It passes if the function property is called exactly once time during the test life span.

    Type parameters

    • T: object

    • K: string | number | symbol

    Parameters

    • property: AnyFunction<any> | K

      The function itself or the name of the function property on the host object (2nd argument)

    • object: T

      The host object

    • Optional desc: string

      The description of the assertion

    Returns void

isntCalled

  • isntCalled<T, K>(property: AnyFunction<any> | K, object: T, desc?: string): void
  • This is a shortcut alias for isCalledNTimes, with the expected argument hardcoded to the 0. It passes if the function property is not called during the test life span.

    Type parameters

    • T: object

    • K: string | number | symbol

    Parameters

    • property: AnyFunction<any> | K

      The function itself or the name of the function property on the host object (2nd argument)

    • object: T

      The host object

    • Optional desc: string

      The description of the assertion

    Returns void

methodIsCalled

  • methodIsCalled<T, K>(property: AnyFunction<any> | K, cls: T, desc?: string): void
  • This is a shortcut alias for methodIsCalledNTimes, with the expected argument hardcoded to >=1. It passes if the method is called at least once during the test life span.

    Type parameters

    Parameters

    • property: AnyFunction<any> | K

      The function itself or the name of the function property on the host object (2nd argument)

    • cls: T
    • Optional desc: string

      The description of the assertion

    Returns void

methodIsCalledNTimes

  • methodIsCalledNTimes<T, K>(property: AnyFunction<any> | K, cls: T, expected: string | number, desc?: string, isGreaterEqual?: boolean): void
  • This assertion passes when the supplied class method is called the expected number of times during the test life span. The expected number of calls can be either a number or a string, consisting from the comparison operator and a number. See [[FiresOkOptions.events]] for more details.

    Under "class method" here we mean the function in the prototype. Note, that this assertion counts calls to the method in any class instance.

    For example:

    class Car {
    constructor (type, version) {
    this.carInfo = {
    type : type,
    version : version
    }
    }

    update (type, version) {
    this.setVersion(type);
    this.setType(version);
    }

    setVersion (data) {
    this.carInfo.version = data;
    }

    setType (data) {
    this.carInfo.type = data;
    }
    };

    t.methodIsCalled("setVersion", Car, "Checking if method 'setVersion' has been called");
    t.methodIsCalled("setType", Car, "Checking if method 'setType' has been called");

    const m = new Car('rover', '0.1.2');

    m.update('3.2.1', 'New Rover');

    This assertion is useful when you need to verify the method calls during class instantiation time, which means you need to observe the prototype method before the instantiation.

    Type parameters

    Parameters

    • property: AnyFunction<any> | K

      The method function itself or its name

    • cls: T

      The class

    • expected: string | number

      The expected number of calls.

    • Optional desc: string

      The description of the assertion

    • Optional isGreaterEqual: boolean

    Returns void

methodIsntCalled

  • methodIsntCalled<T, K>(property: AnyFunction<any> | K, cls: T, desc?: string): void
  • This is a shortcut alias for methodIsCalledNTimes, with the expected argument hardcoded to 0. It passes if the method is not called during the test life span.

    Type parameters

    Parameters

    • property: AnyFunction<any> | K

      The function itself or the name of the function property on the host object (2nd argument)

    • cls: T
    • Optional desc: string

      The description of the assertion

    Returns void

Fuzzy comparison

any

  • any<T>(...args: T): T extends [] ? any : T extends [AnyConstructor<I, object>] ? DowngradePrimitives<I> : never
  • A wrapper for the any fuzzy matcher helper

    Type parameters

    Parameters

    • Rest ...args: T

    Returns T extends [] ? any : T extends [AnyConstructor<I, object>] ? DowngradePrimitives<I> : never

anyArrayContaining

  • anyArrayContaining(expected: unknown[]): []
  • A wrapper for the anyArrayContaining fuzzy matcher helper.

    Parameters

    • expected: unknown[]

    Returns []

anyNumberApprox

  • A wrapper for the anyNumberApprox fuzzy matcher helper.

    Parameters

    Returns number

anyObjectContaining

  • anyObjectContaining(expected: Record<string, unknown>): Record<string, unknown>
  • A wrapper for the anyObjectContaining fuzzy matcher helper.

    Parameters

    • expected: Record<string, unknown>

    Returns Record<string, unknown>

anyStringLike

  • anyStringLike(pattern: string | RegExp): string
  • A wrapper for the anyStringLike fuzzy matcher helper.

    Parameters

    • pattern: string | RegExp

    Returns string

isApprox

  • isApprox(received: number, expected: number, approx?: Approximation, description?: string): void
  • This assertion passes, if the received value is approximately equal to the expected. The notion of "approximate equality" is defined with the approx attribute, which is converted to the NumberApproximation with the NumberApproximation.fromApproximation.

    Parameters

    • received: number
    • expected: number
    • approx: Approximation = ...
    • description: string = ''

    Returns void

Logging

debug

  • debug(...message: unknown[]): void
  • The log method for the debug log level

    Parameters

    • Rest ...message: unknown[]

    Returns void

error

  • error(...message: unknown[]): void
  • The log method for the error log level

    Parameters

    • Rest ...message: unknown[]

    Returns void

info

  • info(...message: unknown[]): void
  • The log method for the info log level

    Parameters

    • Rest ...message: unknown[]

    Returns void

log

  • log(...message: unknown[]): void
  • The log method for the log log level

    Parameters

    • Rest ...message: unknown[]

    Returns void

warn

  • warn(...message: unknown[]): void
  • The log method for the warn log level

    Parameters

    • Rest ...message: unknown[]

    Returns void

Mocking

createSpy

  • createSpy<T>(spyName?: string): T & {}
  • This method create a standalone spy function, which tracks all calls to it. Tracking is done using the associated spy instance, which is available as and property. One can use the Spy class API to verify the calls to the spy function.

    For example:

    const spyFunc     = t.createSpy('onadd listener')

    myObservable.addEventListener('add', spyFunc)

    // do something that triggers the `add` event on the `myObservable`

    t.expect(spyFunc).toHaveBeenCalled()

    t.expect(spyFunc.calls.argsFor(1)).toEqual([ 'Arg1', 'Arg2' ])

    See also: spyOn

    Type parameters

    Parameters

    • spyName: string = 'James Bond'

      A name of the spy for debugging purposes

    Returns T & {}

    Created function. The associated spy instance is assigned to it as the spy property

createSpyObj

  • createSpyObj(properties: ArbitraryObjectKey[]): ArbitraryObject<SpyFunction>
  • This method creates an object, which properties are spy functions. Such object can later be used as a mockup.

    This method can be called with one argument only, which should be an array of properties.

    For example:

    const mockup      = t.createSpyObj('encoder-mockup', [ 'encode', 'decode' ])
    // or just
    const mockup = t.createSpyObj([ 'encode', 'decode' ])

    mockup.encode('string')
    mockup.decode('string')

    t.expect(mockup.encode).toHaveBeenCalled()

    See also: createSpy

    Parameters

    • properties: ArbitraryObjectKey[]

      An array of the property names. For each property name a spy function will be created.

    Returns ArbitraryObject<SpyFunction>

    A mockup object

spyOn

  • spyOn(object: unknown, propertyName: ArbitraryObjectKey): Spy
  • This method installs a "spy" instead of normal function in some object. The "spy" is basically another function, which tracks its calls. With spies, one can verify that some function has been called and that it has been called with certain arguments.

    By default, spy will call the original method and return a value from it. To enable different behavior, you can use one of these methods:

    • returnValue - return a specific value
    • callThrough - call the original method and return a value from it
    • stub - call the original method and return a value from it
    • callFake - call the provided function and return a value from it
    • throwError - throw a specific exception object

    For example:

    // spy that tracks the calls to `process`
    const spy = t.spyOn(obj, 'process')

    // or, if you need to also mock the method
    const spy = t.spyOn(obj, 'process').callFake(() => {
    // is called instead of `process` method
    })

    // call the method
    obj.process('fast', 1)

    t.expect(spy).toHaveBeenCalled();
    t.expect(spy).toHaveBeenCalledWith('fast', 1);

    See also createSpy, createSpyObj, toHaveBeenCalled, toHaveBeenCalledWith

    See also the Spy class for additional details.

    Parameters

    • object: unknown

      An object which property is being spied

    • propertyName: ArbitraryObjectKey

      A name of the property over which to install the spy.

    Returns Spy

    spy Created spy instance

Numeric comparison

isGE

  • isGE(received: unknown, expected: unknown, description?: string): void
  • Alias for isGreaterOrEqual

    Parameters

    • received: unknown
    • expected: unknown
    • description: string = ''

    Returns void

isGreater

  • isGreater(received: unknown, expected: unknown, description?: string): void
  • This assertion passes if the received value is greater than expected, as defined by the > operator. It works for numbers, Dates and other values that overloads the valueOf method.

    Parameters

    • received: unknown
    • expected: unknown
    • description: string = ''

    Returns void

isGreaterOrEqual

  • isGreaterOrEqual(received: unknown, expected: unknown, description?: string): void
  • This assertion passes if the received value is greater or equal than expected, as defined by the >= operator. It works for numbers, Dates and other values that overloads the valueOf method.

    Parameters

    • received: unknown
    • expected: unknown
    • description: string = ''

    Returns void

isLE

  • isLE(received: unknown, expected: unknown, description?: string): void
  • Alias for isLessOrEqual

    Parameters

    • received: unknown
    • expected: unknown
    • description: string = ''

    Returns void

isLess

  • isLess(received: unknown, expected: unknown, description?: string): void
  • This assertion passes if the received value is less than expected, as defined by the < operator. It works for numbers, Dates and other values that overloads the valueOf method.

    Parameters

    • received: unknown
    • expected: unknown
    • description: string = ''

    Returns void

isLessOrEqual

  • isLessOrEqual(received: unknown, expected: unknown, description?: string): void
  • This assertion passes if the received value is less than expected, as defined by the <= operator. It works for numbers, Dates and other values that overloads the valueOf method.

    Parameters

    • received: unknown
    • expected: unknown
    • description: string = ''

    Returns void

Observable assertions

firesAtLeastNTimes

  • firesAtLeastNTimes(observable: ActionTarget, event: string | string[], n: number, description?: string): void
  • This assertion passes if the provided observable triggers the specified event(s) at least N times times during the rest of the test execution.

    This method is a specialized form of the firesOk assertion.

    Parameters

    • observable: ActionTarget

      The observable instance, anything that resolveObservable accepts

    • event: string | string[]

      The name of the event(s)

    • n: number

      The minimum number of events to be fired

    • Optional description: string

      Assertion description

    Returns void

firesOk

  • firesOk(options: FiresOkOptions<ActionTarget>): any
  • firesOk(observable: ActionTarget, events: string, expected: string | number, description?: string): any
  • firesOk(observable: ActionTarget, events: string, expected: string | number, during: number | AnyFunction<any>, description?: string): any
  • firesOk(observable: ActionTarget, events: Record<string, string | number>, description?: string): any
  • firesOk(observable: ActionTarget, events: Record<string, string | number>, during: number | AnyFunction<any>, description?: string): any
  • This assertion counts the number of events, triggered by the provided observable instance, during the provided period and compares it with the expected numbers. The period is specified with the during option and can be:

    • execution of the provided function (which can possibly be async)
    • time period, in milliseconds
    • the rest of the test (if not provided).

    The exact notion of what the observable is, is defined by the resolveObservable method.

    This method has several overloads. Normally it accepts a single object with various options:

    await t.firesOk({
    observable : document.body,
    events : {
    mousedown : 2,
    mouseup : 2,
    click : '> 1',
    dblclick : '== 1'
    },
    during : async () {
    await t.click([ 100, 100 ])
    },
    desc : 'Correct double click events fired'
    })

    This method also can be called in 2 additional shortcuts forms:

    // shortcut form, multiple events
    t.firesOk(observable, { event1 : 1, event2 : '>1' }, description)

    // shortcut form, single event
    t.firesOk(observable, eventName, 1, during?, description)
    t.firesOk(observable, eventName, '>1', during?, description)

    Parameters

    Returns any

  • Parameters

    • observable: ActionTarget
    • events: string
    • expected: string | number
    • Optional description: string

    Returns any

  • Parameters

    • observable: ActionTarget
    • events: string
    • expected: string | number
    • during: number | AnyFunction<any>
    • Optional description: string

    Returns any

  • Parameters

    • observable: ActionTarget
    • events: Record<string, string | number>
    • Optional description: string

    Returns any

  • Parameters

    • observable: ActionTarget
    • events: Record<string, string | number>
    • during: number | AnyFunction<any>
    • Optional description: string

    Returns any

firesOnce

  • firesOnce(observable: ActionTarget, event: string | string[], description?: string): void
  • This assertion passes if the provided observable triggers the specified event(s) exactly 1 time during the rest of the test execution.

    This method is a specialized form of the firesOk assertion.

    Parameters

    • observable: ActionTarget

      The observable instance, anything that resolveObservable accepts

    • event: string | string[]

      The name of the event(s)

    • Optional description: string

      Assertion description

    Returns void

isntFired

  • isntFired(observable: ActionTarget, event: string | string[], description?: string): void
  • Alias for wontFire method

    Parameters

    • observable: ActionTarget
    • event: string | string[]
    • Optional description: string

    Returns void

waitForEvent

  • This assertion passes, if the provided observable, triggers the specified event within the timeout and fails otherwise. The timeout can be specified using the object argument, if not provided the TestDescriptor.waitForTimeout is used.

    Parameters

    Returns Promise<void>

willFireNTimes

  • willFireNTimes(observable: ActionTarget, event: string | string[], expected: string | number, description?: string): void
  • This assertion passes if the provided observable triggers the specified event(s) exactly N times during the rest of the test execution.

    This method is a specialized form of the firesOk assertion.

    Parameters

    • observable: ActionTarget

      The observable instance, anything that resolveObservable accepts

    • event: string | string[]

      The name of the event(s)

    • expected: string | number

      Expected number of events

    • Optional description: string

      Assertion description

    Returns void

wontFire

  • wontFire(observable: ActionTarget, event: string | string[], description?: string): void
  • This assertion passes if the provided observable does not trigger the specified event(s) during the rest of the test execution.

    This method is a specialized form of the firesOk assertion.

    Parameters

    • observable: ActionTarget

      The observable instance, anything that resolveObservable accepts

    • event: string | string[]

      The name of the event(s)

    • Optional description: string

      Assertion description

    Returns void

Other

constructor

  • Parameters

    • Rest ...input: any[]

    Returns TestBrowser

logLevel

logLevel: LogLevel = LogLevel.log

The current log level, the logger operates at.

testDescriptorClass

testDescriptorClass: typeof TestDescriptorBrowser

contain

  • contain<V>(iterable: Iterable<V>, element: V, description?: string): void
  • This assertion passes if the provided iterable contains the element value. The element comparison is performed deeply.

    Type parameters

    • V

    Parameters

    • iterable: Iterable<V>
    • element: V
    • description: string = ''

    Returns void

initialize

  • initialize<T>(props?: Partial<T>): void
  • 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.

    Type parameters

    Parameters

    • Optional props: Partial<T>

    Returns void

notContain

  • notContain<V>(iterable: Iterable<V>, element: V, description?: string): void
  • This assertion passes if the provided iterable does not contain the element value. The element comparison is performed deeply.

    Type parameters

    • V

    Parameters

    • iterable: Iterable<V>
    • element: V
    • description: string = ''

    Returns void

resolveObservable

  • Parameters

    Returns unknown

Static maybeNew

  • maybeNew<T>(props?: InstanceType<T> | Partial<InstanceType<T>>): InstanceType<T>
  • 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.

    Type parameters

    Parameters

    • Optional props: InstanceType<T> | Partial<InstanceType<T>>

    Returns InstanceType<T>

Static new

  • new<T>(props?: Partial<InstanceType<T>>): InstanceType<T>
  • 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.

    Type parameters

    Parameters

    • Optional props: Partial<InstanceType<T>>

    Returns InstanceType<T>

String pattern matching

match

  • match(string: string, pattern: string | RegExp, desc?: string): void
  • This assertion passes when provided string matches the given pattern.

    The pattern can be a RegExp instance or string, in the latter case the provided string should contain the pattern as a substring.

    Parameters

    • string: string
    • pattern: string | RegExp
    • desc: string = ''

    Returns void

notMatch

  • notMatch(string: string, pattern: string | RegExp, desc?: string): void
  • This assertion passes when provided string does not matches the given pattern.

    The pattern can be a RegExp instance or string, in the latter case the provided string should not contain the pattern as a substring.

    Parameters

    • string: string
    • pattern: string | RegExp
    • desc: string = ''

    Returns void

Subtest management

afterEach

  • This method allows you to execute some "cleanup" code hook after every "it" section of the current test. It is usually used to clear some global resource, used by the tests. Sometimes it is actually more convenient, instead of clearing the resource in the afterEach do that in the beforeEach, after checking that resource has been allocated. In this way, if you'll be debugging some individual test section, the resource will still be available after the test completion.

    it sections can be nested, and hooks can be added at every level. afterEach hooks are executed starting from the innermost level.

    The 1st argument of the hook function is always the test instance being launched.

    If the hook function is async Siesta will await until it completes.

    This method can be called several times, providing several hook functions to execute.

    import { it, beforeEach } from "@bryntum/siesta/index.js"

    let file
    beforeEach(async () => file = await OPEN_FILE())
    afterEach(async () => await CLOSE_FILE(file))

    it('Test section', async t => {
    const content = await READ_FILE(file)
    })

    Backward compatibility. The hook function also accepts an optional second argument, which is a callback, which should be called, indicating that hook execution has complete. If it is provided, Siesta will await both for any promise returned from the hook function and for the call to callback.

    Parameters

    Returns void

beforeEach

  • This method allows you to execute some "setup" code hook before every "it" section of the current test. It is usually used to restore some global state to the predefined value.

    it sections can be nested, and hooks can be added at every level. beforeEach hooks are executed starting from the outermost level.

    The 1st argument of the hook function is always the test instance being launched.

    If the hook function is async Siesta will await until it completes.

    This method can be called several times, providing several hook functions to execute.

    import { it, beforeEach } from "@bryntum/siesta/index.js"

    let sum

    beforeEach(async t => sum = 0)

    it('Test section #1', async t => {
    sum++
    t.equal(sum, 1)
    })

    it('Test section #2', async t => {
    sum += 2
    t.equal(sum, 2)
    })

    Backward compatibility. The hook function also accepts an optional second argument, which is a callback, which should be called, indicating that hook execution has complete. If it is provided, Siesta will await both for any promise returned from the hook function and for the call to callback.

    Parameters

    Returns void

ddescribe

  • An alias for iit

    Parameters

    Returns TestBrowser

describe

  • An alias for it

    Parameters

    Returns TestBrowser

iit

  • This is an "exclusive" version of the regular it test section. When such exclusive section is found, the other regular test sections at the same level will not be executed, only "exclusive" ones.

    Parameters

    Returns TestBrowser

it

  • This method creates a "parent" node in the test file, grouping assertions together. Such node is called "test section" or "sub-test". Sub-tests can be nested arbitrarily.

    The 1st argument for this method can be either a string or a configuration object for this test's descriptor. The string value corresponds to { title : 'string_value' }.

    The configuration object of the nested test section "extends" the configuration object of the parent section.

    For example if parent section sets the defaultTimeout to a certain value, the nested section will use that value too.

    import { it } from "@bryntum/siesta/index.js"

    it({ title : 'Test section', defaultTimeout : 1000 }, async t => {
    t.it('Nested test section', async t => {
    // will fail within 1s
    await t.waitFor(() => false)
    })
    })

    See also iit, xit methods to quickly isolate/exclude a test section.

    To create a top-level test section, the it function or it static method should be used. These aliases can actually be used inside the test function as well, however it is recommended to use the method on the test instance.

    import { it, Test } from "@bryntum/siesta/index.js"

    it('Test section', async (t : Test) => {
    t.it({ title : 'Nested section', isTodo : true }, async (t : Test) => {
    ...
    })
    })

    // The following two lines are identical
    it('Test section', async (t : Test) => { ... }) // `it` function
    Test.it('Test section', async (t : Test) => { ... }) // static `Test.it` method

    Parameters

    Returns TestBrowser

todo

  • This method has the same functionality as it, plus it sets the isTodo config of the test descriptor to true.

    Parameters

    Returns TestBrowser

xit

  • This is a no-op method, allowing you to quickly ignore some test sections - just add x ("exclude") to the section call.

    Parameters

    Returns TestBrowser

Static ddescribe

  • ddescribe<T>(name: TestDescriptorArgument<InstanceType<T>>, code: (t: InstanceType<T>) => any): InstanceType<T>
  • Alias for Test.iit.

    Type parameters

    Parameters

    • name: TestDescriptorArgument<InstanceType<T>>
    • code: (t: InstanceType<T>) => any
        • (t: InstanceType<T>): any
        • Parameters

          • t: InstanceType<T>

          Returns any

    Returns InstanceType<T>

Static describe

  • describe<T>(name: TestDescriptorArgument<InstanceType<T>>, code: (t: InstanceType<T>) => any): InstanceType<T>
  • Alias for Test.it.

    Type parameters

    Parameters

    • name: TestDescriptorArgument<InstanceType<T>>
    • code: (t: InstanceType<T>) => any
        • (t: InstanceType<T>): any
        • Parameters

          • t: InstanceType<T>

          Returns any

    Returns InstanceType<T>

Static iit

  • Alias for Test.iit. Should be used for top-level sub-tests only.

    Type parameters

    Parameters

    • name: TestDescriptorArgument<InstanceType<T>>
    • code: (t: InstanceType<T>) => any
        • (t: InstanceType<T>): any
        • Parameters

          • t: InstanceType<T>

          Returns any

    Returns InstanceType<T>

Static it

  • Static alias for Test.it. Should be used for top-level sub-tests only. Can be useful if you create your own subclass of the test class.

    Type parameters

    Parameters

    • name: TestDescriptorArgument<InstanceType<T>>
    • code: (t: InstanceType<T>) => any
        • (t: InstanceType<T>): any
        • Parameters

          • t: InstanceType<T>

          Returns any

    Returns InstanceType<T>

Static xdescribe

  • xdescribe<T>(name: TestDescriptorArgument<InstanceType<T>>, code: (t: InstanceType<T>) => any): InstanceType<T>
  • Alias for Test.xit.

    Type parameters

    Parameters

    • name: TestDescriptorArgument<InstanceType<T>>
    • code: (t: InstanceType<T>) => any
        • (t: InstanceType<T>): any
        • Parameters

          • t: InstanceType<T>

          Returns any

    Returns InstanceType<T>

Static xit

  • Alias for Test.xit. Should be used for top-level sub-tests only.

    Type parameters

    Parameters

    • name: TestDescriptorArgument<InstanceType<T>>
    • code: (t: InstanceType<T>) => any
        • (t: InstanceType<T>): any
        • Parameters

          • t: InstanceType<T>

          Returns any

    Returns InstanceType<T>

Typeguards

isArray

  • isArray(value: unknown, description?: string): void
  • This assertion passes if the received value is a Array.

    Parameters

    • value: unknown
    • description: string = ''

    Returns void

isBoolean

  • isBoolean(value: unknown, description?: string): void
  • This assertion passes if the received value is a Boolean.

    Parameters

    • value: unknown
    • description: string = ''

    Returns void

isDate

  • isDate(value: unknown, description?: string): void
  • This assertion passes if the received value is a Date.

    Parameters

    • value: unknown
    • description: string = ''

    Returns void

isFunction

  • isFunction(value: unknown, description?: string): void
  • This assertion passes if the received value is a Function.

    Parameters

    • value: unknown
    • description: string = ''

    Returns void

isInstanceOf

  • isInstanceOf(value: unknown, cls: AnyConstructor<object, object>, description?: string): void
  • This assertion passes if the received value is an instance of the cls class. It works for native built-in classes too.

    For example:

    t.isInstanceOf([ 1, 2, 3 ], Array)

    t.isInstanceOf(1, Number)

    Parameters

    • value: unknown

      The received value

    • cls: AnyConstructor<object, object>

      The class constructor

    • description: string = ''

    Returns void

isMap

  • isMap(value: unknown, description?: string): void
  • This assertion passes if the received value is a Map.

    Parameters

    • value: unknown
    • description: string = ''

    Returns void

isNumber

  • isNumber(value: unknown, description?: string): void
  • This assertion passes if the received value is a Number.

    Parameters

    • value: unknown
    • description: string = ''

    Returns void

isObject

  • isObject(value: unknown, description?: string): void
  • This assertion passes if the received value is a Object.

    Parameters

    • value: unknown
    • description: string = ''

    Returns void

isRegExp

  • isRegExp(value: unknown, description?: string): void
  • This assertion passes if the received value is a RegExp.

    Parameters

    • value: unknown
    • description: string = ''

    Returns void

isSet

  • isSet(value: unknown, description?: string): void
  • This assertion passes if the received value is a Set.

    Parameters

    • value: unknown
    • description: string = ''

    Returns void

isString

  • isString(value: unknown, description?: string): void
  • This assertion passes if the received value is a String.

    Parameters

    • value: unknown
    • description: string = ''

    Returns void

isWeakMap

  • isWeakMap(value: unknown, description?: string): void
  • This assertion passes if the received value is a WeakMap.

    Parameters

    • value: unknown
    • description: string = ''

    Returns void

isWeakSet

  • isWeakSet(value: unknown, description?: string): void
  • This assertion passes if the received value is a WeakSet.

    Parameters

    • value: unknown
    • description: string = ''

    Returns void

User action simulation

click

  • Simulates a click on the given ActionTarget at the given ActionTargetOffset point. If offset is not provided the action happens in the center of the visible part of the target element.

    Before performing an action, Siesta waits for the target element to become actionable and synchronize the cursor position.

    This method has 2 overloads and target and offset can be given either as positional arguments, or in the form of the MouseActionOptions object.

    For example:

    await t.click('.css-class .another-css.class', [ 30, 40 ])
    await t.click('.css-class .another-css.class', { offset : [ 30, 40 ], ctrlKey : true })
    await t.click({ target : '.css-class .another-css.class', offset : [ 30, 40 ], ctrlKey : true })

    A special case of

    await t.click()
    

    is equivalent to t.click([]) - clicking at the current cursor location.

    Parameters

    Returns Promise<any>

  • Parameters

    Returns Promise<any>

doubleClick

  • Simulates a double click on the given ActionTarget at the given ActionTargetOffset point. If offset is not provided the action happens in the center of the visible part of the target element.

    Before performing an action, Siesta waits for the target element to become actionable and synchronize the cursor position.

    This method has 2 overloads and target and offset can be given either as positional arguments, or in the form of the MouseActionOptions object.

    For example:

    await t.doubleClick('.css-class .another-css.class', [ 30, 40 ])
    await t.doubleClick('.css-class .another-css.class', { offset : [ 30, 40 ], ctrlKey : true })
    await t.doubleClick({ target : '.css-class .another-css.class', offset : [ 30, 40 ], ctrlKey : true })

    A special case of

    await t.doubleClick()
    

    is equivalent to t.doubleClick([]) - clicking at the current cursor location.

    Parameters

    Returns Promise<any>

  • Parameters

    Returns Promise<any>

dragBy

  • Simulates a drag action, from the given source element, by the given delta.

    For example:

    await t.dragBy('#source', [ 10, 20 ], { ctrlKey : true })
    await t.dragBy([], [ 10, 20 ], { ctrlKey : true }) // drag from current cursor position

    Parameters

    Returns Promise<any>

dragTo

  • Simulates a drag action, from the source element, to the target element

    This method has several overloads and source and target can be provided either as positional arguments, or as properties of the DragActionOptions object.

    For example:

    await t.dragTo('#source', '#target', { ctrlKey : true })
    await t.dragTo({ source : '#source', target : '#target', ctrlKey : true })

    Parameters

    Returns Promise<any>

  • Parameters

    Returns Promise<any>

keyDown

  • Simulates a key down action on the given target element.

    For example:

    await t.keyDown('#source', 's')
    

    Parameters

    Returns Promise<any>

keyPress

  • Simulates a single key press on the given target element.

    For example:

    await t.keyPress('#source', 's', { ctrlKey : true })
    

    Parameters

    Returns Promise<any>

keyUp

  • Simulates a key up action on the given target element.

    For example:

    await t.keyUp('#source', 's')
    

    Parameters

    Returns Promise<any>

mouseDown

  • Simulates a "mouse down" action on the given ActionTarget at the given ActionTargetOffset point. If offset is not provided the action happens in the center of the visible part of the target element.

    Before performing an action, Siesta waits for the target element to become actionable and synchronize the cursor position.

    This method has 2 overloads and target and offset can be given either as positional arguments, or in the form of the MouseActionOptions object.

    For example:

    await t.mouseDown('.css-class .another-css.class', [ 30, 40 ])
    await t.mouseDown('.css-class .another-css.class', { offset : [ 30, 40 ], ctrlKey : true })
    await t.mouseDown({ target : '.css-class .another-css.class', offset : [ 30, 40 ], ctrlKey : true })

    A special case of

    await t.mouseDown()
    

    is equivalent to t.mouseDown([]) - clicking at the current cursor location.

    Parameters

    Returns Promise<any>

  • Parameters

    Returns Promise<any>

mouseUp

  • Simulates a "mouse up" action on the given ActionTarget at the given ActionTargetOffset point. If offset is not provided the action happens in the center of the visible part of the target element.

    Before performing an action, Siesta waits for the target element to become actionable and synchronize the cursor position.

    This method has 2 overloads and target and offset can be given either as positional arguments, or in the form of the MouseActionOptions object.

    For example:

    await t.mouseUp('.css-class .another-css.class', [ 30, 40 ])
    await t.mouseUp('.css-class .another-css.class', { offset : [ 30, 40 ], ctrlKey : true })
    await t.mouseUp({ target : '.css-class .another-css.class', offset : [ 30, 40 ], ctrlKey : true })

    A special case of

    await t.mouseUp()
    

    is equivalent to t.mouseUp([]) - clicking at the current cursor location.

    Parameters

    Returns Promise<any>

  • Parameters

    Returns Promise<any>

moveMouseBy

  • Simulates a relative "mouse move" action, from the current position, by the given delta.

    This method has several overloads and delta can be provided either as a Point or 2 positional arguments.

    For example:

    await t.moveMouseBy(30, 40)
    await t.moveMouseBy([ 30, 40 ], { ctrlKey : true })

    Parameters

    Returns Promise<any>

  • Parameters

    Returns any

moveMouseTo

  • Simulates "mouse move" action to the given ActionTarget at the given ActionTargetOffset point. If offset is not provided, cursor moves to the center of the visible part of the target element.

    Before performing mouse move, Siesta waits for the target element to become actionable.

    This method has several overloads and target and offset can be given either as positional arguments, or in the form of the MouseActionOptions object.

    For example:

    await t.moveMouseTo(30, 40)
    await t.moveMouseTo([ 30, 40 ])
    await t.moveMouseTo('.css-class .another-css.class', [ 30, 40 ])
    await t.moveMouseTo('.css-class .another-css.class', { offset : [ 30, 40 ], ctrlKey : true })
    await t.moveMouseTo({ target : '.css-class .another-css.class', offset : [ 30, 40 ], ctrlKey : true })

    Parameters

    Returns Promise<any>

  • Parameters

    Returns any

  • Parameters

    Returns any

rightClick

  • Simulates a right click on the given ActionTarget at the given ActionTargetOffset point. If offset is not provided the action happens in the center of the visible part of the target element.

    Before performing an action, Siesta waits for the target element to become actionable and synchronize the cursor position.

    This method has 2 overloads and target and offset can be given either as positional arguments, or in the form of the MouseActionOptions object.

    For example:

    await t.rightClick('.css-class .another-css.class', [ 30, 40 ])
    await t.rightClick('.css-class .another-css.class', { offset : [ 30, 40 ], ctrlKey : true })
    await t.rightClick({ target : '.css-class .another-css.class', offset : [ 30, 40 ], ctrlKey : true })

    A special case of

    await t.rightClick()
    

    is equivalent to t.rightClick([]) - clicking at the current cursor location.

    Parameters

    Returns Promise<any>

  • Parameters

    Returns Promise<any>

type

  • Simulates keyboard typing on the given target element. Performs all actions that a real user would do, including pressing and releasing a keyboard button for every character.

    If target is provided as [] or null, the typing will be performed on the currently focused element. Otherwise, target will be resolved and focused.

    Simulation of pressing the special keys is supported. You can specify them, by using their all uppercased key name inside the square brackets: [ENTER], [BACKSPACE], [LEFT]. To type [ENTER] as plain text and not as a special character - use double square brackets: [[ENTER]]. The full list of special key names is available here.

    To specify a control key like "SHIFT / CONTROL / ALT / META" of to be pressed during typing, use the options argument.

    For example:

    await t.type('#source', 'some text[ENTER]', { ctrlKey : true })
    

    Parameters

    Returns Promise<any>

Generated using TypeDoc