Menu

class: TestHarness

[50:7] extends: object

tharness.aus Component test harness. Provides an isolated mount container, helpers to mount, find, interact with, and unmount a single UI component, and a clean teardown so multiple test methods can share one setUp. Usage: class MyTests { h = null; @Before public setUp() { this.h = new TestHarness(); } @After public tearDown() { this.h.destroy(); } @Test(name = "renders the name") public rendersName() { this.h.mount(new HelloBadge("Sarah")); test.expectElementText(".hello-badge", "Hello, Sarah"); } } Every TestHarness creates its own div with id "test-harness-mount" and appends it to document.body. find / findAll queries are scoped to that div so a stale component left behind by a sibling test cannot leak into queries.

Members

  • container

    The test container Div this harness mounted into the body.

  • mounted

    The last mount()-ed HNode.

Methods

  • TestHarness ()

    Construct. Creates a detached container Div with a known id and appends it to document.body so the component under test sees a real live DOM subtree.

  • mount (Node)

    Mount one component into the harness container. Replaces any previously-mounted component in the same container so multiple test methods can share one setUp.

    • @p Node Any HNode (typically a component under test).
    • @r The mounted HNode.
  • destroy ()

    Tear down. Removes the container from the document; safe to call twice.

    • @r this object
  • find (string Selector)

    CSS selector query scoped to the harness container.

    • @p Selector CSS selector.
    • @r HNode or null.
  • findAll (string Selector)

    CSS selector query returning every match, scoped to the harness container.

    • @p Selector CSS selector.
    • @r List of HNode (possibly empty).
  • resolve (SelectorOrEl)

    Resolve a selector or HNode argument to an HNode. Selectors are scoped to the harness container.

    • @p SelectorOrEl CSS selector or HNode.
    • @r HNode.
  • click (SelectorOrEl)

    Fire a real "click" event on the matching element. Listeners attached via HNode.addListener are invoked.

    • @p SelectorOrEl CSS selector or HNode.
    • @r this object
  • fill (SelectorOrEl, string Value)

    Set the value of an input / textarea / select-like element and fire "input" and "change" events so listeners observe the change the same way they would for a real user keystroke.

    • @p SelectorOrEl CSS selector or HNode.
    • @p Value Value to set.
    • @r this object
  • selectOption (SelectorOrEl, string OptionValue)

    Select an option in a