You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can spy on console.log after activating emulator.start to read logs in tests:
it('given a transaction: logs out the signers',async()=>{constmessage='Hello from Emulator';constAlice=awaitgetAccountAddress('Alice');constBob=awaitgetAccountAddress('Bob');constsigners=[Alice,Bob];constconsoleSpy=jest.spyOn(console,'log')// eslint-disable-next-line @typescript-eslint/no-empty-function.mockImplementation(()=>{});emulator.setLogging(true);awaitsendTransaction({name: 'log-signers',args: [message],
signers,});consttransactionLogs=consoleSpy.mock.calls.toString();consoleSpy.mockRestore();constactual=[transactionLogs.includes(message),transactionLogs.includes(Alice),transactionLogs.includes(Bob),];constexpected=[true,true,true];expect(actual).toEqual(expected);});
Trade-offs between 1 and 2
Solution 2 works already (except for a bug that malformats addresses in logs).
Solution 1 would be more clean and doesn't need extensive knowledge of your testing framework. However, it would require additional dev work to implement. It would also make debugging easier.
(Optional): Context
I'm writing tests for a project to get familiar with Flow. In the future these tests will assert program correctness.
The text was updated successfully, but these errors were encountered:
Issue To Be Solved
When you log inside a transaction there is no easy way to access those logs inside of your code / tests.
(Optional): Suggest A Solution
Solution 1: add logs to the return value of
sendTransaction
Currently,
sendTransaction
returns an object with 4 keys.We could add a fifth value
logs
Solution 2: use
spyOn
onconsole.log
You can spy on
console.log
after activatingemulator.start
to read logs in tests:Trade-offs between 1 and 2
Solution 2 works already (except for a bug that malformats addresses in logs).
Solution 1 would be more clean and doesn't need extensive knowledge of your testing framework. However, it would require additional dev work to implement. It would also make debugging easier.
(Optional): Context
I'm writing tests for a project to get familiar with Flow. In the future these tests will assert program correctness.
The text was updated successfully, but these errors were encountered: