Hybrid View

  1. #1
    Sencha User
    Join Date
    Aug 2010
    Posts
    6
    Vote Rating
    0
    extjs.ben is on a distinguished road

      0  

    Default 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?

    Thanks,
    Ben

  2. #2
    Sencha - Ext JS Dev Team
    Join Date
    Jun 2011
    Location
    San Diego, CA
    Posts
    205
    Vote Rating
    40
    nohuhu has a spectacular aura about nohuhu has a spectacular aura about nohuhu has a spectacular aura about

      0  

    Default


    Ben,

    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.

    Regards,
    Alex.

  3. #3
    Sencha User
    Join Date
    Aug 2010
    Posts
    6
    Vote Rating
    0
    extjs.ben is on a distinguished road

      0  

    Default


    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)

    sync_call = (async_method, args, callback, test_case) ->
    latch = false
    async_args = null


    # 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()
    ...

    Cheers,
    Ben

Thread Participants: 1