diff --git a/src/testing/harness.ts b/src/testing/harness.ts index 6caa58109..73cfbd551 100644 --- a/src/testing/harness.ts +++ b/src/testing/harness.ts @@ -133,16 +133,19 @@ export function harness( trigger(selector: string, functionSelector: string | FunctionalSelector, ...args: any[]): any { _tryRender(); const [firstItem] = select(selector, _getRender()); - if (firstItem) { - let triggerFunction: Function | undefined; - if (typeof functionSelector === 'string') { - triggerFunction = (firstItem.properties as any)[functionSelector]; - } else { - triggerFunction = functionSelector(firstItem); - } - if (triggerFunction) { - return triggerFunction.apply(widget, args); - } + + if (!firstItem) { + throw new Error(`Cannot find node with selector ${selector}`); + } + + let triggerFunction: Function | undefined; + if (typeof functionSelector === 'string') { + triggerFunction = (firstItem.properties as any)[functionSelector]; + } else { + triggerFunction = functionSelector(firstItem); + } + if (triggerFunction) { + return triggerFunction.apply(widget, args); } }, getRender(index?: number): DNode | DNode[] { diff --git a/tests/testing/unit/harness.ts b/tests/testing/unit/harness.ts index 20414d2ab..54db33ae3 100644 --- a/tests/testing/unit/harness.ts +++ b/tests/testing/unit/harness.ts @@ -271,18 +271,7 @@ describe('harness', () => { w('registry-item', { key: 'registry', id: 'random-id' }) ]) ); - h.trigger('*[key="other"]', 'onclick'); - h.expect(() => - v('div', { classes: ['root', 'other'], onclick: () => {} }, [ - v( - 'span', - { key: 'span', classes: 'span', style: 'width: 100px', id: 'random-id', onclick: () => {} }, - ['hello 0'] - ), - w(ChildWidget, { key: 'widget', id: 'random-id', func: noop }), - w('registry-item', { key: 'registry', id: 'random-id' }) - ]) - ); + assert.throws(() => h.trigger('*[key="other"]', 'onclick')); }); it('trigger by pseudo selector', () => { @@ -520,14 +509,9 @@ describe('harness', () => { it('trigger with non matching selector', () => { const h = harness(() => w(ArrayWidget, {})); - h.trigger('*[key="other"]', 'onclick'); - h.expect(() => [ - v('span', { key: 'span', classes: 'span', style: 'width: 100px', id: 'random-id', onclick: () => {} }, [ - 'hello 0' - ]), - w(ChildWidget, { key: 'widget', id: 'random-id' }), - w('registry-item', { key: 'registry', id: 'random-id' }) - ]); + assert.throws(() => { + h.trigger('*[key="other"]', 'onclick'); + }); }); it('custom compare for VNode', () => { diff --git a/tests/testing/unit/harnessWithTsx.tsx b/tests/testing/unit/harnessWithTsx.tsx index cfd3c0b8c..827a580f3 100644 --- a/tests/testing/unit/harnessWithTsx.tsx +++ b/tests/testing/unit/harnessWithTsx.tsx @@ -1,4 +1,5 @@ const { describe, it } = intern.getInterface('bdd'); +const { assert } = intern.getPlugin('chai'); import { harness } from '../../../src/testing/harness'; import { WidgetBase } from '../../../src/widget-core/WidgetBase'; @@ -181,16 +182,8 @@ describe('harness with tsx', () => { it('trigger with non matching selector', () => { const h = harness(() => ); - h.trigger('*[key="other"]', 'onclick'); - h.expect(() => ( -
- - hello 0 - - - -
- )); + + assert.throws(() => h.trigger('*[key="other"]', 'onclick')); }); it('custom compare for VNode', () => {