# Jest: Unexpected token 'export'

**URL:** <https://community.sendbird.com/t/jest-unexpected-token-export/5899>\
**Category:** JavaScript\
**Tags:** react-js\
**Created:** [November 9, 2022, 3:00pm UTC](https://community.sendbird.com/t/jest-unexpected-token-export/5899 "2022-11-09T15:00:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Floflo18](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/floflo18/32/3245_2.png) [@Floflo18](https://community.sendbird.com/u/Floflo18)\
**Post date:** [November 9, 2022, 3:00pm UTC](https://community.sendbird.com/t/jest-unexpected-token-export/5899/1 "2022-11-09T15:00:11Z")

</div>

## **[Problem/Question]** Hi ! When I run my tests using Jest, I got an `SyntaxError: Unexpected token ‘export’` from `node_modules/@sendbird/chat/sendbird.js:1`. I tried to add `transformIgnorePatterns` and `moduleNameMapper` to my jest config but it doesn’t work and I didn’t find any topic/thread about that. Can you help me with that please ? ![Capture d’écran 2022-11-09 à 15.41.23](https://us1.discourse-cdn.com/flex020/uploads/sendbird/original/2X/c/c4d246b2adf8fc23cda58688cdb43f077b0e9c0c.png)

// If problem, please fill out the below. If question, please delete.  
**[SDK Version]**  
@sendbird/chat 4.1.0  
**[Reproduction Steps]**

- Import something from @sendbird/chat
- Run tests with jest  
**[Frequency]**  
Always  
**[Current impact]**  
Blocking

---

<div class="post-metadata">

**Author:** ![edmundsj](https://avatars.discourse-cdn.com/v4/letter/e/b782af/32.png) [@edmundsj](https://community.sendbird.com/u/edmundsj)\
**Post date:** [November 28, 2022, 4:47pm UTC](https://community.sendbird.com/t/jest-unexpected-token-export/5899/2 "2022-11-28T16:47:34Z")

</div>

I am having the same issue. Running with jest and react-testing-library. My jest.config.js (I tried to get jest to ignore sendbird, but to no avail):

```auto
const config = { 
    testEnvironment: 'jsdom',
    moduleDirectories: ['node_modules', 'src'],
    moduleNameMapper: {
      "\\.(jpg|ico|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<r ootDir>/mocks/fileMock.js",
      "\\.(css|less|scss|sass)$": "<rootDir>/mocks/fileMock.js"
    },  
    setupFilesAfterEnv: ["@testing-library/jest-dom/extend-expect"],
    transformIgnorePatterns: [
        "node_modules/(?!@sendbird)"                                                                
    ]   
}

module.exports = config;

```

Build is managed by `create-react-app`, node version 18.8.0, jest 27.5.1, react 18.2.0.

---

<div class="post-metadata">

**Author:** ![edmundsj](https://avatars.discourse-cdn.com/v4/letter/e/b782af/32.png) [@edmundsj](https://community.sendbird.com/u/edmundsj)\
**Post date:** [November 28, 2022, 5:15pm UTC](https://community.sendbird.com/t/jest-unexpected-token-export/5899/3 "2022-11-28T17:15:05Z")

</div>

I got it to run by explicitly adding the `--transformIgnorePatterns "node_modules/(?!@sendbird)/chat"` as a flag to `react-scripts test`. However, because sendbird now has to compile every time I run my tests, they take about 2GB of memory and 100% of my quad-core CPU for a good 30 seconds, which is just not sustainable when I have to run tests constantly.

Until the sendbird team pre-compiles their node module into standard JS with `module.exports` instead of `export {}` syntax, I’m afraid this makes it infeasible for me to use.

---

<div class="post-metadata">

**Author:** ![Alexis\_Le\_Boucher](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/alexis_le_boucher/32/3243_2.png) [@Alexis\_Le\_Boucher](https://community.sendbird.com/u/Alexis_Le_Boucher)\
**Post date:** [December 2, 2022, 9:52am UTC](https://community.sendbird.com/t/jest-unexpected-token-export/5899/4 "2022-12-02T09:52:05Z")

</div>

You can also mock sendbird, here the code I used to mock sendbird chat and groupChannels :

```auto
/* eslint-disable object-shorthand */
/* eslint-disable @typescript-eslint/no-empty-function */
import '@testing-library/jest-dom/extend-expect';

const channels = [
    {
        members: [
            {
                userId: '9878f560-0499-4db1-89d8-782717e32d7f',
            },
            {
                userId: '76bf72cc-0e5f-41a2-a209-b097a36d3bd5',
            },
        ],
        url: 'sendbird_group_channel_url1',
        unreadMessageCount: 1,
        lastMessage: {
            createdAt: 1668000173366,
            sender: {
                userId: '76bf72cc-0e5f-41a2-a209-b097a36d3bd5',
                nickname: 'Alex Chat',
            },
            message: 'Hey!',
        },
    },
    {
        members: [
            {
                userId: '9878f560-0499-4db1-89d8-782717e32d7f',
            },
            {
                userId: '76bf72cc-0e5f-41a2-a209-b097a36d3bd5',
            },
        ],
        url: 'sendbird_group_channel_url2',
        unreadMessageCount: 1,
        lastMessage: {
            createdAt: 1668000173366,
            sender: {
                userId: '76bf72cc-0e5f-41a2-a209-b097a36d3bd5',
                nickname: 'Alex Chat',
            },
            message: 'Message!',
        },
    },
];

jest.mock('@sendbird/chat', () => {
    return {
        __esModule: true,
        default: {
            init: (p: any) => {
                return {
                    addUserEventHandler: (p: any, p2: any) => {},
                    setSessionHandler: (p: any) => {},
                    removeUserEventHandler: (p: any) => {},
                    connect: (p: any, a: any) => {},
                    groupChannel: {
                        addGroupChannelHandler: (p: any, p2: any) => {},
                        removeGroupChannelHandler: (p: any) => {},
                        getTotalUnreadMessageCount: () => 2,
                        createMyGroupChannelListQuery: (p: any) => ({
                            hasNext: true,
                            next: () => channels,
                        }),
                    },
                };
            },
        },
        SessionHandler: jest.fn().mockImplementation(() => {
            return {};
        }),
        UserEventHandler: jest.fn().mockImplementation(() => {
            return {};
        }),
    };
});

jest.mock('@sendbird/chat/groupChannel', () => {
    return {
        __esModule: true,
        GroupChannel: {},
        GroupChannelCreateParams: {},
        GroupChannelHandler: jest.fn().mockImplementation(() => {
            return {};
        }),
        GroupChannelListOrder: {},
        GroupChannelListQuery: {},
        GroupChannelListQueryParams: {},
        GroupChannelModule: jest.fn().mockImplementation(() => {
            return {};
        }),
        MyMemberStateFilter: {},
        SendbirdGroupChat: {},
        GroupChannelHideParams: {},
    };
});

jest.mock('@sendbird/chat/message', () => {
    return {
        __esModule: true,
        BaseMessage: {},
        FileMessage: {},
        MessageModule: jest.fn().mockImplementation(() => {
            return {};
        }),
        MessageTypeFilter: {},
        ReplyType: {},
    };
});

```

It returns 2 fake Group Channels bu you can also return fake messages using this logic

---

<div class="post-metadata">

**Author:** ![Ronen\_Meiri](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/ronen_meiri/32/2227_2.png) [@Ronen\_Meiri](https://community.sendbird.com/u/Ronen_Meiri)\
**Post date:** [July 14, 2024, 12:15pm UTC](https://community.sendbird.com/t/jest-unexpected-token-export/5899/5 "2024-07-14T12:15:17Z")

</div>

any update regarding this case ? we are also experiencing this after upgrading to v4 and sendbird-desk 1.1.2
