It would be useful to see the RedisGetAction code here, as I think I'd
expect the failure -- were the mock clock working incorrectly -- to be
that you *never* go to the ready state (if waiting is the default),
rather than getting to ready right away.
I'm assuming RedisGetAction calls get on the client stub on
construction, right?
The other offhand things I could think of:
1) you're ticking the clock in some other before that is applied to
this test and jasmine may decide that you've already ticked past 1500,
so runs your code immediately
2) you're using some other library that interacts poorly with the mock
clock (I have heard of some mocking add-ons that seem to have issues
here).
Thanks!
Rajan
On Wed, Oct 31, 2012 at 11:02 PM, Brandon Wilburn
<
techie....@yahoo.com> wrote:
> I hate to repost across multiple forums but I haven't get any response from
> Stackoverflow so thought it worth a shot here.
>
>
http://stackoverflow.com/questions/13167741/jasmine-coffeescript-clock-not-effective
>
> I am getting no joy from my jasmine.Clock. My expectation is that the code
> will mock out the clock object and will trigger setTimeout events upon
> setting the tick past the specified intervals in the setTimeout, however
> this does not seem to be working and I cannot find my flaw. My code seems to
> be parallel to others applying the same clock control behavior.
>
> Background: the 'callback' function sets the this.action.state() to
> Constants.state.Ready after execution, prior it should be
> Constants.state.WAITING. Please note I am using knockout observables; the
> state is supposed to be called as a fx to retrieve value.
>
> describe "Redis GET Action", () ->
> beforeEach () ->
> jasmine.Clock.useMock();
> this.getReturnValue = getReturnValue = "Some jasmine values from redis"
> clientStub =
> get: (key,callback) ->
> if callback?
> setTimeout(callback(undefined, getReturnValue),1500)
> GET: (key,callback) ->
> if callback?
> setTimeout(callback(undefined, getReturnValue),1500)
>
> this.action = new RedisGetAction(
> client: clientStub
> key: "Standard"
> )
>
>
> it "should return a object", () ->
> expect(this.action).toEqual(jasmine.any(Object))
>
> requiredMethods = ['state','data','params'];
>
> requiredMethods.forEach (methodName) ->
> it "should have public "+methodName+" method", () ->
> expect(this.action[methodName]).toBeDefined();
>
> it "should initialize with public accessible state of
> #{Constants.state.WAITING}", () ->
> expect(this.action.state()).toEqual(Constants.state.WAITING)
> jasmine.Clock.tick(1501);
> expect(this.action.state()).toEqual(Constants.state.READY)
>
> Results: Failures:
>
> 1) should initialize with public accessible state of waiting
> Message:
> Expected 'ready' to equal 'waiting'.
> Stacktrace:
> Error: Expected 'ready' to equal 'waiting'.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Jasmine" group.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/jasmine-js/-/KvIHndF2l34J.
> To post to this group, send email to
jasmi...@googlegroups.com.
> To unsubscribe from this group, send email to
>
jasmine-js+...@googlegroups.com.
> For more options, visit this group at
>
http://groups.google.com/group/jasmine-js?hl=en.