flow-js-testing icon indicating copy to clipboard operation
flow-js-testing copied to clipboard

Update docs to include how to deal with events

Open alilloig opened this issue 2 years ago • 0 comments

Issue To Be Solved

Checking the data emitted by an event is possible using the js testing framework but is not showcased on the docs

Suggest A Solution

Include a subsection on the Send Transactions section telling how to it and including a little example.

Message from Amit explaining how it works

when executing a transaction, the result from its promise contains an events array which should give you it. some old code of mine which should mostly work still, except might be result[0].events instead of result.events:

result = await shallPass(await sendTransaction({
      code: cadenceCode,
      signers: [ accountA ],
      args: [ null, 2, 1, 1, 1, (tomorrow.getTime() / 1000).toString() ],
      addressMap: addressMap
    }))

    expect(result.events.length).toBe(2)
    expect(result.events[0].type.indexOf('ZayTrader.TradeCollectionInitialized') > 0).toBe(true)
    expect(result.events[1].type.indexOf('ZayTrader.TradeOfferAvailable') > 0).toBe(true)

This is how result[0].events looks like with a single event

[
    {
        "data": {"sequence": "0", "versionTable": {"15": {"isBackwardsCompatible": true, "major": "0", "minor": "1", "patch": "2", "preRelease": "alpha.1"}}}, 
        "eventIndex": 0, 
        "transactionId": "a0f210b5f0710dac3a02071b3a5492501bb02aabdb88e132a3b41f3e576cb6c3", 
        "transactionIndex": 1, "type": "A.01cf0e2f2f715450.NodeVersionBeacon.NodeVersionTableUpdated"
    }
]

alilloig avatar Jan 13 '23 14:01 alilloig