Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I suggest your testing will be more robust / useful if it concentrates on <em>behaviour</em> as opposed to implementation. In this case, it would make more sense to test if your widget responds to the topic (or better still, the event that causes the topic to be published, for more of an integration test) rather than attempting to catch the subscription itself.</p> <p>Of course, you could try and wrap topic.subscribe (bad thing), or inspect your widget's private list of handles (another bad thing). Incidentally, I hope you are in fact saving the handle returned by topic.subscribe so that you can remove (previously, unsubscribe) it later when the object is destroyed.</p> <p>Better than those would be to simply make a new object, publish to that topic, and see if doSomething is called, or if the desired result has occurred. While doh does not provide support for listening to function calls, dojo/aspect is ideal for this purpose. So you might have something like this :</p> <pre><code>var myWidget = new myWidget(); // presumably subscription happened, // but we only care about later behaviour var somethingDone = false; aspect.after(window, "doSomething", function(){somethingDone = true;}); topic.publish(CustomTopic.TOPIC_STRING()); doh.assertTrue(somethingDone); </code></pre> <p>In fact, I assume doSomething is not a global method, so you'll have to scope that properly, but otherwise this should work fine. Currently topic.publish is synchronous, so this should work fine, but it could become async in the future, in which case you would want to avoid calling doh.assertTrue until some later stage.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload