File

src/lib/test-html-element.ts

Description

A wrapped DOM HTML element, providing additional methods and attributes helping with writing tests

Extends

TestElement

Index

Properties
Methods

Constructor

constructor(tester: ComponentTester, debugElement: DebugElement)
Parameters :
Name Type Optional
tester ComponentTester<any> no
debugElement DebugElement no

Properties

Public Readonly debugElement
debugElement: DebugElement
Type : DebugElement
Inherited from TestElement
Defined in TestElement:20

the wrapped debug element

Methods

click
click()

Clicks on the wrapped element, then triggers a change detection

Returns : void
attr
attr(name: string)
Inherited from TestElement
Defined in TestElement:62

Gets the attribute of the wrapped element with the given name

Parameters :
Name Type Optional Description
name string no

the name of the attribute to get

Returns : any
button
button(selector: string)
Inherited from TestElement
Defined in TestElement:123

Gets the first button matched by the given selector. Throws an Error if the matched element isn't actually a button.

Parameters :
Name Type Optional Description
selector string no

a CSS selector

Returns : TestButton | null

the wrapped button, or null if no element was matched

dispatchEvent
dispatchEvent(event: Event)
Inherited from TestElement
Defined in TestElement:46

dispatches the given event from the wrapped element, then triggers a change detection

Parameters :
Name Type Optional
event Event no
Returns : void
dispatchEventOfType
dispatchEventOfType(type: string)
Inherited from TestElement
Defined in TestElement:38

dispatches an event of the given type from the wrapped element, then triggers a change detection

Parameters :
Name Type Optional
type string no
Returns : void
element
element(selector: string)
Inherited from TestElement
Defined in TestElement:74

Gets the first element matching the given CSS selector and wraps it into a TestElement. The actual type of the returned value is the TestElement subclass matching the type of the found element. So, if the matched element is an input for example, the method will return a TestInput. You can thus use tester.element('#some-input') as TestInput.

Parameters :
Name Type Optional Description
selector string no

a CSS selector

Returns : TestElement | null

the wrapped element, or null if no element matches the selector.

elements
elements(selector: string)
Inherited from TestElement
Defined in TestElement:86

Gets all the elements matching the given CSS selector and wraps them into a TestElement. The actual type of the returned elements is the TestElement subclass matching the type of the found element. So, if the matched elements are inputs for example, the method will return an array of TestInput. You can thus use tester.elements('input') as Array<TestInput>.

Parameters :
Name Type Optional Description
selector string no

a CSS selector

the array of matched elements, empty if no element was matched

input
input(selector: string)
Inherited from TestElement
Defined in TestElement:95

Gets the first input matched by the given selector. Throws an Error if the matched element isn't actually an input.

Parameters :
Name Type Optional Description
selector string no

a CSS selector

Returns : TestInput | null

the wrapped input, or null if no element was matched

select
select(selector: string)
Inherited from TestElement
Defined in TestElement:104

Gets the first select matched by the given selector. Throws an Error if the matched element isn't actually a select.

Parameters :
Name Type Optional Description
selector string no

a CSS selector

Returns : TestSelect | null

the wrapped select, or null if no element was matched

textarea
textarea(selector: string)
Inherited from TestElement
Defined in TestElement:114

Gets the first textarea matched by the given selector

Parameters :
Name Type Optional Description
selector string no

a CSS selector

the wrapped textarea, or null if no element was matched. Throws an Error if the matched element isn't actually a textarea.

import { ComponentTester } from './component-tester';
import { TestElement } from './test-element';
import { DebugElement } from '@angular/core';

/**
 * A wrapped DOM HTML element, providing additional methods and attributes helping with writing tests
 */
export class TestHtmlElement<E extends HTMLElement> extends TestElement<E> {
  constructor(tester: ComponentTester<any>, debugElement: DebugElement) {
    super(tester, debugElement);
  }

  /**
   * Clicks on the wrapped element, then triggers a change detection
   */
  click() {
    this.nativeElement.click();
    this.tester.detectChanges();
  }
}

results matching ""

    No results matching ""