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'.