By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,483 Members | 1,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,483 IT Pros & Developers. It's quick & easy.

Is there jsmock implementaion?

P: n/a
Can anybody point me to some jsmock implementation? My attempt to
google it failed :(

Oct 1 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"alex_gilboa" <al********@gmail.com> writes:
Can anybody point me to some jsmock implementation? My attempt to
google it failed :(


Google gives no results on "jsmock", so unless you tell us what such a
"jsmock" implementation should do, it's hard to say whether one exists
that satisfies your needs.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Oct 1 '05 #2

P: n/a
Oh, sorry for so unintelligible question. I've meant mock objects
implementation for javascript. Mock objects are used for isolating
tests in unit testing. (see e.g.
www.connextra.com/aboutUs/mockobjects.pdf)

Oct 1 '05 #3

P: n/a
"alex_gilboa" <al********@gmail.com> writes:
Oh, sorry for so unintelligible question. I've meant mock objects
implementation for javascript.


While there might be a framework for helping with this somewhere,
Javascript objects are so easily customizable that it's probably not
necessary.

If you need an object that returns three different names from a call
to getName, you could just write:

{index : 0,
getName : function() {
return ["Tim","Tom","Jack"][this.index++];
}}

Since Javascript objects doesn't have a type, they don't have to go
through hoops to look like a specific type of objects. If need be,
they can havve their prototype chain set to emulate a specific
constructor.
---
function mock(constructor) {
function Dummy(){};
Dummy.prototype=constructor.prototype;
return new Dummy();
}
---
If you want to change the behavior of existing objects, you can
just clone them and add properties to the clone:
---
function clone(object) {
function Dummy(){};
Dummy.prototype = object;
return new Dummy();
}

var o = {foo:42, bar: "I said 42!"};
var oc = clone(o);
oc.foo = 37;

alert([o.foo, o.bar, oc.foo, oc.bar]);
---

If this is enough for you, there is no need for mockery :)
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Oct 2 '05 #4

P: n/a
Thank you for your answer.

But I seek for just framework that have usual (for nUnit users)
interface. I found only implementation. It is in Selenium test
framework. They are using it for _internal_ testing purposes. It isn't
an independent public project and implementation is very unpretentious.
It's important for me to have possibility write my tests in such a
manner:

collaborator = new Mock();
collaborator.expects("dispatch, "foo").returns(true);
collaborator.expects("dispatch, "bar").returns(true);

objectUnderTest = new MyClass(collaborator);
objectUnderTest .process("foo", "bar");

collaborator.verify();

If objectUnderTest will not call serially method dispatch with given
arguments the test will fail.

Selenium is accessible on
http://gforge.public.thoughtworks.or...nium-0.6.0.zip

Mock implementation is in selenium-0.6.0\selenium\jsmock directory.

Oct 3 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.