# Testing - TypeError: Cannot destructure property 'events' of 'e' as it is null

**URL:** <https://forum.flow.com/t/testing-typeerror-cannot-destructure-property-events-of-e-as-it-is-null/3085>\
**Category:** Uncategorized\
**Created:** [May 7, 2022, 8:55am UTC](https://forum.flow.com/t/testing-typeerror-cannot-destructure-property-events-of-e-as-it-is-null/3085 "2022-05-07T08:55:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pzak](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@Pzak](https://forum.flow.com/u/Pzak)\
**Post date:** [May 7, 2022, 8:55am UTC](https://forum.flow.com/t/testing-typeerror-cannot-destructure-property-events-of-e-as-it-is-null/3085/1 "2022-05-07T08:55:22Z")

</div>

Hello, I’m new to Flow and I’m trying to write a very simple test.  
But when I try to use `const Alice = await getAccountAddress('alice')`  
I’m getting the error: **"TypeError: Cannot destructure property ‘events’ of ‘e’ as it is null"**

My test is very simple. So I’m probably missing something but I don’t know what

Here is my test:

```auto

import path from "path";
import { emulator, init, getAccountAddress } from "flow-js-testing";

// Increase timeout if your tests failing due to timeout
jest.setTimeout(10000);

describe("Token", () => {
    beforeEach(async () => {
        const basePath = path.resolve(__dirname, "../cadence");
        // You can specify different port to parallelize execution of describe blocks
        const port = 8888;
        // Setting logging flag to true will pipe emulator output to console
        const logging = false;

        await init(basePath, { port });
        return emulator.start(port, logging);
    });

    // Stop emulator, so it could be restarted
    afterEach(async () => {
        return emulator.stop();
    })

    test("Alice should exist", async () => {
        const Alice = await getAccountAddress('alice')
        expect(Alice).toBeDefined()
    })
});

```

The error:

```auto
› Alice should exist

    TypeError: Cannot destructure property 'events' of 'e' as it is null.

      23 |
      24 | test("Alice should exist", async () => {
    > 25 | const Alice = await getAccountAddress('alice')
         | ^
      26 | expect(Alice).toBeDefined()
      27 | })
      28 | });

      at events (node_modules/flow-js-testing/src/account.js:64:19)
      at Object.<anonymous> (cadence/tests/ZooToken.test.ts:25:23)

```

---

<div class="post-metadata">

**Author:** ![bluesign](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/bluesign/32/1359_2.png) [@bluesign](https://forum.flow.com/u/bluesign)\
**Post date:** [May 7, 2022, 4:19pm UTC](https://forum.flow.com/t/testing-typeerror-cannot-destructure-property-events-of-e-as-it-is-null/3085/2 "2022-05-07T16:19:57Z")

</div>

do you have flow.json in project root?

> <https://github.com/onflow/flow-js-testing/blob/1e35afb0cc1dd8d512e9e450b54827ddfb2b6ddd/docs/generator.md>

---

<div class="post-metadata">

**Author:** ![phill](https://avatars.discourse-cdn.com/v4/letter/p/779978/32.png) [@phill](https://forum.flow.com/u/phill)\
**Post date:** [May 9, 2022, 12:35pm UTC](https://forum.flow.com/t/testing-typeerror-cannot-destructure-property-events-of-e-as-it-is-null/3085/3 "2022-05-09T12:35:01Z")

</div>

I often see this error if I have another instance of the Flow emulator running - check that you don’t have another terminal open with the emulator running inside of it. If you do, shut that one down and run your test again

---

<div class="post-metadata">

**Author:** ![Pzak](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@Pzak](https://forum.flow.com/u/Pzak)\
**Post date:** [May 13, 2022, 10:59am UTC](https://forum.flow.com/t/testing-typeerror-cannot-destructure-property-events-of-e-as-it-is-null/3085/4 "2022-05-13T10:59:37Z")

</div>

I have generated my testing suite with `npx flow-js-testing init`.  
I have a flow.json file at my project’s root:

```auto
	"emulators": {
		"default": {
			"port": 3569,
			"serviceAccount": "emulator-account"
		}
	},
	"contracts": {
		"ZooToken": "./cadence/contracts/ZooToken.sol",
		"FungibleToken": "./cadence/contracts/FungibleToken.sol"
	},
	"networks": {
		"emulator": "127.0.0.1:3569",
		"mainnet": "access.mainnet.nodes.onflow.org:9000",
		"testnet": "access.devnet.nodes.onflow.org:9000"
	},
	"accounts": {
		"emulator-account": {
			"address": "f8d6e0586b0a20c7",
			"key": "0cea21d8c33b62bd84d5684a2630406b79ed7330558058e1b933b9178382be4e"
		},
		"alice": {
			"address": "179b6b1cb6755e31",
			"key": "bfa4823cec2f11864585124c9ea5d7e7832bd2bb6ce29e3db5f2ae6763a82086"
		}
	},
	"deployments": {
		"emulator-account": ["FungibleToken", "ZooToken"]
	}
}

```

And I don’t have a running emulator. I’m just running jest.

My test fail only if I add this line: `const Alice = await getAccountAddress('alice')`. It looks like the function cannot create a new account

---

<div class="post-metadata">

**Author:** ![bluesign](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/bluesign/32/1359_2.png) [@bluesign](https://forum.flow.com/u/bluesign)\
**Post date:** [May 15, 2022, 8:20am UTC](https://forum.flow.com/t/testing-typeerror-cannot-destructure-property-events-of-e-as-it-is-null/3085/5 "2022-05-15T08:20:30Z")

</div>

Sorry only today had time to debug, just change port number in test from 8888, it is used by REST API on emulator now. 8080 etc should work.

---

<div class="post-metadata">

**Author:** ![Pzak](https://avatars.discourse-cdn.com/v4/letter/p/e9c0ed/32.png) [@Pzak](https://forum.flow.com/u/Pzak)\
**Post date:** [May 19, 2022, 12:49pm UTC](https://forum.flow.com/t/testing-typeerror-cannot-destructure-property-events-of-e-as-it-is-null/3085/6 "2022-05-19T12:49:32Z")

</div>

I tried to switch to the port 8088, and verified that it’s not used and still have the same issue

---

<div class="post-metadata">

**Author:** ![bluesign](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.flow.com/bluesign/32/1359_2.png) [@bluesign](https://forum.flow.com/u/bluesign)\
**Post date:** [May 20, 2022, 7:27am UTC](https://forum.flow.com/t/testing-typeerror-cannot-destructure-property-events-of-e-as-it-is-null/3085/7 "2022-05-20T07:27:46Z")

</div>

another option can be flow-cli version, this error is mostly related when Emulator is not running on that selected port etc.

you can try to verify but watching `ps ax | grep flow` and catching launch arguments (quickest way) and trying to run with that arguments to see the error.
