# Unit tests with Webpack

**URL:** <https://discourse.aurelia.io/t/unit-tests-with-webpack/4258>\
**Category:** Help Requests\
**Created:** [June 15, 2021, 5:32am UTC](https://discourse.aurelia.io/t/unit-tests-with-webpack/4258 "2021-06-15T05:32:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkowalski](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@jkowalski](https://discourse.aurelia.io/u/jkowalski)\
**Post date:** [June 15, 2021, 5:32am UTC](https://discourse.aurelia.io/t/unit-tests-with-webpack/4258/1 "2021-06-15T05:32:08Z")

</div>

Hi  
Is there any possiblity to run async unit tests with Webpack?  
All the time I’m getting **webpack\_require** ☹  
And I can’t fix it.  
We are using webpack in whole project and everything works, but not in unit tests.

---

<div class="post-metadata">

**Author:** ![TomasKulhanek](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/tomaskulhanek/32/1726_2.png) [@TomasKulhanek](https://discourse.aurelia.io/u/TomasKulhanek)\
**Post date:** [June 16, 2021, 7:13am UTC](https://discourse.aurelia.io/t/unit-tests-with-webpack/4258/2 "2021-06-16T07:13:40Z")

</div>

It’s hard to determine from the description as `webpack_require` seems weird to be thrown from unit tests. Could you create and share some sample project with aurelia, webpack and sample test replicating your issue? I have a project with aurelia+webpack and unit tests testing some async call - however, I catch the promise and handle it with `.then( x=> {... done()}) .catch( e=>{ faile(e);done();});`.

---

<div class="post-metadata">

**Author:** ![jkowalski](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@jkowalski](https://discourse.aurelia.io/u/jkowalski)\
**Post date:** [June 16, 2021, 12:41pm UTC](https://discourse.aurelia.io/t/unit-tests-with-webpack/4258/3 "2021-06-16T12:41:30Z")

</div>

Tomas, please check my last comment here:

> [@Problem with executing unit test](https://discourse.aurelia.io/t/problem-with-executing-unit-test/4255/5):
>
> In my case it doesn’t work neither with “aurelia-framework” (info from documentation) nor “aurelia-pal” frowning import {bootstrap} from 'aurelia-bootstrapper'; import {StageComponent} from 'aurelia-testing'; import {PLATFORM} from 'aurelia-pal'; describe('Testing nav-bar', () =\> { let component; let navBarBinding; beforeEach(() =\> { navBarBinding = { state: { showNav: false }, nav: null }; component = S…

---

<div class="post-metadata">

**Author:** ![eagle](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@eagle](https://discourse.aurelia.io/u/eagle)\
**Post date:** [June 17, 2021, 6:16am UTC](https://discourse.aurelia.io/t/unit-tests-with-webpack/4258/4 "2021-06-17T06:16:55Z")

</div>

Hi @jkowalski,

Sure, it is possible, we’re using async unit tests with webpack.  
The testing framework we’re using is jest, and the syntax looks like this:

```auto
it('my async test', (done) => {
            myAsyncMethod().then((result) => {
                expect(result).toBe(1);
                done();
            });
        });

```

And the jest-setup file looks like this:

```auto
import { Options } from 'aurelia-loader-nodejs';
import { globalize } from 'aurelia-pal-nodejs';
import 'aurelia-polyfills';
import * as path from 'path';

Options.relativeToDir = path.join(__dirname, 'unit');

globalize();

```

---

<div class="post-metadata">

**Author:** ![jkowalski](https://avatars.discourse-cdn.com/v4/letter/j/a183cd/32.png) [@jkowalski](https://discourse.aurelia.io/u/jkowalski)\
**Post date:** [June 17, 2021, 8:48am UTC](https://discourse.aurelia.io/t/unit-tests-with-webpack/4258/5 "2021-06-17T08:48:41Z")

</div>

Still nothing 😕

Our jest-pretest.js looks like this:

```auto
import 'aurelia-polyfills';
import 'aurelia-loader-webpack';
import {initialize} from 'aurelia-pal-browser';
import 'jest';
initialize();

```

And jest-preprocess.js:

```auto
const babelOptions = {
    presets: [
        [
            "@babel/preset-env",
            {
                "targets": {
                    "node": "current"
                }
            }
        ]
    ],
};

module.exports = require("babel-jest").createTransformer(babelOptions);

```

Tests works, but not with webpack (e.g. testing promises) 😕

---

<div class="post-metadata">

**Author:** ![eagle](https://avatars.discourse-cdn.com/v4/letter/e/ba8739/32.png) [@eagle](https://discourse.aurelia.io/u/eagle)\
**Post date:** [May 25, 2022, 8:37am UTC](https://discourse.aurelia.io/t/unit-tests-with-webpack/4258/6 "2022-05-25T08:37:21Z")

</div>

Missed that one, could you solve it @jkowalski ?

Else let me know how the jest setup in package.json looks like
