Get help with testing, discuss unit testing strategies etc.

Post by Kurt »

I am trying to figure out if an event has been received.
I know that the event is catched and runs MyApp.util.Barcode.onBarcodeScanned.

Here is my code:

                "Checking if method 'onBarcodeScanned' has been called"

           // this works 
           // this does not work
           Ext.fireEvent('barcodeScanned', 'T|123123123');

           // to allow for more time after the event fired
            t.waitForMs(500, () => {
                t.describe('init', function(t) {})

If I fire the event from the console, it works.
Any idea what to change?

Last edited by Kurt on Wed Oct 11, 2023 2:06 pm, edited 1 time in total.

Post by nickolay »


You mentioned the SmartMobile.util.Barcode.onBarcodeScanned('T|123123123'); works, which means Siesta correctly intercepts the onBarcodeScanned method in the MyApp.util.Barcode object.

As regarding Ext.fireEvent('barcodeScanned', 'T|123123123'); - this is something specific to your application, sorry, can't say anything about this.

Post by Kurt »

I believe it is not about my app.

Running Ext.fireEvent('barcodeScanned') works fine.
I am getting a console.log from the onBarcodeScanned, but it is not captured by isCalled.

Any other ideas?

Post by Kurt »

I found the problem:

    onBarcodeScanned      => gets created by isCalled
        onBarcodeScanned  => original Function, which was set to Ext.on('barcodeScanned', ...)

Looks like the Ext.on saves the original method and isCalled uses the newly created one.

Any ideas, what I can do to figure out if the function got called?

Post by nickolay »

Right, this is the order of capturing the onBarcodeScanned method.

The only proper way would be to load your application code first (w/o launching it), install the override in the class'es prototype, then launch the app (so that the app captures the override).

But may be you can test some other side effect of the onBarcodeScanned method call?

Post by Kurt »

You were right. I can test if the globalEvent has been set.

Instead of :

// I know that this is the  only listener on barcodescanned
let l0 =['barcodescanned'].listeners[0];

t.isCalled("fireFn", l0, "Checking if method 'onBarcodeScanned' has been called");

Ext.fireEvent('barcodeScanned', 'T|123123123');

I can use:



Post Reply