Is there jsmock implementaion?

A

alex_gilboa

Can anybody point me to some jsmock implementation? My attempt to
google it failed :(
 
L

Lasse Reichstein Nielsen

alex_gilboa said:
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
 
L

Lasse Reichstein Nielsen

alex_gilboa said:
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]);
 
A

alex_gilboa

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.org/download.php/51/selenium-0.6.0.zip

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top