optional sychronous function call (for unit testing with less line noise)
optional sychronous function call (for unit testing with less line noise)
Is there an easy way to call an Ext.Direct method synchronously? In general I have no need for this but it would make automated testing of my remote method api easier/more straightforward ...
I'd like to be able to write something like Ext.Direct.synchronous_call(app.rpc.server_func, server_func_callback, other_args...)
and have the 'synchronous_call' method call not return until after the asynchronous callback has executed ... I'd tolerate some kind of ugly console output on each such call warning not to use this method except for testing purposes so that it doesn't encourage people to misuse synchronous methods in their browser applications ... Thoughts?
Not sure if that would fit your bill but take a look at Perl module RPC::ExtDirect::Client. I wrote it exactly for the purpose of server API testing, except that I prefer to do it on the server as well.
Thanks for the heads up -- but I'm not a big perl person and trying to integrate my 'remote api' testing with the rest of my client application testing ...
I'm using the jasmine javascript testing library (which is great i must say!) I just made my own 'synchronous_call' helper function which keeps the testcases relatively clean (coffeescript below)
# modified callback with 'latch' (to capture when its been run) and to capture the arguments passed
# to the async_call for future testing by the test function
mod_callback = () ->
latch = true
async_args = arguments
callback(async_args)
runs ->
async_method args, mod_callback
waitsFor( () -> latch)
runs( () -> test_case(async_args) )
And an example call:
args = {'a': 12}
sync_call app.remote.Action.func, args, Ext.emptyFn, (response) ->
# test case executed after ext direct function returns
expect(response[0].data).toBeDefined()
...