Skip to content

New testing helper: mockDOMResponse()

Compare
Choose a tag to compare
@staltz staltz released this 12 Sep 15:24
· 321 commits to master since this release

Added mockDOMResponse(mockedSelectors).

A testing utility which aids in creating a queryable collection of Observables. Call mockDOMResponse giving it an object specifying selectors, eventTypes and their Observabls, and get as output an object following the
same format as the DOM Driver's response.

Example:

// Create the mocked user events
const userEvents = mockDOMResponse({
  '.foo': {
    'click': Rx.Observable.just({target: {}}),
    'mouseover': Rx.Observable.just({target: {}})
  },
  '.bar': {
    'scroll': Rx.Observable.just({target: {}})
  }
});

// Use them in your tests against `main`
const requests = main({DOM: userEvents});

requests.DOM.subscribe(function (vtree) {
  // make assertions on vtree
});

Read more in the docs.