File

src/lib/test-input.ts

Description

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

Extends

TestHtmlElement

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 TestHtmlElement
Defined in TestHtmlElement:20

the wrapped debug element

Methods

check
check()

Checks the wrapped input, then dispatches an event of type change and triggers a change detection

Returns : void
fillWith
fillWith(value: string)

Sets the value of the wrapped input, then dispatches an event of type input and triggers a change detection

Parameters :
Name Type Optional Description
value string no

the new value of the input

Returns : void
uncheck
uncheck()

Unchecks the wrapped input, then dispatches an event of type change and triggers a change detection

Returns : void
click
click()
Inherited from TestHtmlElement
Defined in TestHtmlElement:16

Clicks on the wrapped element, then triggers a change detection

Returns : void
attr
attr(name: string)
Inherited from TestHtmlElement
Defined in TestHtmlElement: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 TestHtmlElement
Defined in TestHtmlElement: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 TestHtmlElement
Defined in TestHtmlElement: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 TestHtmlElement
Defined in TestHtmlElement: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 TestHtmlElement
Defined in TestHtmlElement: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 TestHtmlElement
Defined in TestHtmlElement: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 TestHtmlElement
Defined in TestHtmlElement: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 TestHtmlElement
Defined in TestHtmlElement: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 TestHtmlElement
Defined in TestHtmlElement: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.

Accessors

value
getvalue()

the value of the wrapped input

checked
getchecked()

the checked property of the wrapped input

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

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

  /**
   * Sets the value of the wrapped input, then dispatches an event of type input and triggers a change detection
   * @param value the new value of the input
   */
  fillWith(value: string) {
    this.nativeElement.value = value;
    this.dispatchEventOfType('input');
  }

  /**
   * the value of the wrapped input
   */
  get value() {
    return this.nativeElement.value;
  }

  /**
   * the checked property of the wrapped input
   */
  get checked() {
    return this.nativeElement.checked;
  }

  /**
   * Checks the wrapped input, then dispatches an event of type change and triggers a change detection
   */
  check() {
    this.nativeElement.checked = true;
    this.dispatchEventOfType('change');
  }

  /**
   * Unchecks the wrapped input, then dispatches an event of type change and triggers a change detection
   */
  uncheck() {
    this.nativeElement.checked = false;
    this.dispatchEventOfType('change');
  }
}

results matching ""

    No results matching ""