This reminds me of the jasmine BBD testing framework.  You can do
this.

expect(result).toEqual(expected)

Have a look at the code for some ideas.

On Mar 6, 4:56 am, "Claus Reinke" <[email protected]> wrote:
> >> result.shouldEqual(expected);
> ..
> >> Now, the key thing is that I'd like to have an extension on any object
> >> be it string, Integer or regular object to internally call one of the
> >> QUnit methods (in this case equal(result, expected);
>
> >> I have been playing with something like: Object.prototype.shouldEqual
> ..
> > That's actually exactly how it works. Maybe the missing link is how you
> > call/define `equal`?
>
> I thought it was considered bad style to extend Object.prototype,
> as that is shared by every other script/library in scope? In ES3,
> new properties even leak into enumerations (for (var i in x) ..).
>
> Why not define a wrapper function instead, that delegates to your
> testing methods? You'd write:
>
>     $(result).shouldEqual(expected);
>
> where the function '$' would return a wrapper object that
> implements 'shouldEqual', knows about the wrapped object,
> and delegates to 'equal'. Something like:
>
> function equal(a,b) { return a+' equals '+b;}
>
> function $(obj) {
>   return { shouldEqual: function(other) {
>               return equal(obj,other);
>             }
>          };
>
> }
>
> function log(msg) {
>  if (typeof console!='undefined')
>    console.log(msg);
>  else if (typeof WScript!='undefined')
>    WScript.StdOut.WriteLine(msg);
>
> }
>
> log( $(1).shouldEqual("1") ); // not really
>
> Claus

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to