Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Assert.isUndefined() and Assert.isNotUndefined() in YUI3?
    primarykey
    data
    text
    <p>I'm trying to test for the presence of a declared, defined function using the YUI3 Test framework. In Safari and FireFox, trying to use isNotUndefined, isUndefined, or isFunction fails. I expect those to throw an exception that can be handled by the test framework.</p> <pre><code> Y Object Y.Assert Object Y.Assert.isNotUndefined(x, "fail message") ReferenceError: Can't find variable: x Y.Assert.isUndefined(x, "fail message") ReferenceError: Can't find variable: x Y.Assert.isFunction(x, "fail message") ReferenceError: Can't find variable: x </code></pre> <p>But, instead, I never get to see the failure messages, and the remainder of the tests do not run, because of the interpreter getting in the way... Doesn't that undermine the purpose of these functions, or am I misunderstanding the framework?</p> <p>My intuition tells me that, given the code above and only the code above,</p> <pre><code> Y.Assert.isUndefined(x, "fail message") </code></pre> <p>should continue on without an error (because x is undeclared) and</p> <pre><code> Y.Assert.isNotUndefined(x, "fail message") </code></pre> <p>should log the message "fail message" (because x is undeclared).</p> <p>However, because of the ReferenceError, there's no way (using those YUI3 methods) to test for undeclared objects. Instead, I'm left with some pretty ugly assertion code. I can't use</p> <pre><code> Y.Assert.isNotUndefined(x) ReferenceError: Can't find variable: x </code></pre> <p>or</p> <pre><code> Y.assert( x !== undefined ) ReferenceError: Can't find variable: x </code></pre> <p>which leaves me with </p> <pre><code> Y.assert( typeof(x) !== "undefined" ) // the only working option I've found Assert Error: Assertion failed. </code></pre> <p>which is much less readable than </p> <pre><code> Y.Assert.isNotUndefined(x) </code></pre> <p>Again, I ask: Doesn't that undermine the purpose of these functions, or am I misunderstanding the framework? </p> <p>So</p> <pre><code> x </code></pre> <p>is undeclared, and so not directly testable, while</p> <pre><code> var x; </code></pre> <p>declares it, but leaves it undefined. Finally</p> <pre><code> var x = function() {}; </code></pre> <p>is both declared and defined.</p> <p>I think that what's missing for me is the ability to easily say</p> <pre><code> Y.Assert.isNotUndeclared(x); </code></pre> <p>-Wil</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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