# Constructor not called in Aurelia 2 components tests

**URL:** <https://discourse.aurelia.io/t/constructor-not-called-in-aurelia-2-components-tests/5454>\
**Category:** vNext\
**Created:** [June 13, 2024, 6:55am UTC](https://discourse.aurelia.io/t/constructor-not-called-in-aurelia-2-components-tests/5454 "2024-06-13T06:55:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mreiche](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/mreiche/32/1912_2.png) [@mreiche](https://discourse.aurelia.io/u/mreiche)\
**Post date:** [June 13, 2024, 6:55am UTC](https://discourse.aurelia.io/t/constructor-not-called-in-aurelia-2-components-tests/5454/1 "2024-06-13T06:55:32Z")

</div>

I have a component

```typescript
export class Echart {
    private _container: HTMLDivElement;

    constructor() {
        console.log("Hallo")
    }

```

and set a breakpoint at `constructor()` but it will never created unless a I add a `@customComponent` decorator.

```typescript
@customElement({
    name: 'echart'
})
export class Echart {
    private _container: HTMLDivElement;

    constructor() {
        console.log("Hallo")
    }

```

---

<div class="post-metadata">

**Author:** ![bigopon](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bigopon/32/18_2.png) [@bigopon](https://discourse.aurelia.io/u/bigopon)\
**Post date:** [June 13, 2024, 2:54pm UTC](https://discourse.aurelia.io/t/constructor-not-called-in-aurelia-2-components-tests/5454/2 "2024-06-13T14:54:55Z")

</div>

How does your test code look like? Maybe a more complete set of code should help. I would guess you didn’t even use this chart component.

---

<div class="post-metadata">

**Author:** ![mreiche](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/mreiche/32/1912_2.png) [@mreiche](https://discourse.aurelia.io/u/mreiche)\
**Post date:** [June 14, 2024, 6:09am UTC](https://discourse.aurelia.io/t/constructor-not-called-in-aurelia-2-components-tests/5454/3 "2024-06-14T06:09:18Z")

</div>

This works here: [Aurelia 2 Component Test - StackBlitz](https://stackblitz.com/edit/au2-conventions-xzsu2z) but not in my local environment. It the exact same code, but the `bound()` method never gets called until I add `@customElement("echart")`.

After adding that, `bound()` gets called, but the `ref` element remains _undefined_. Is there something wrong with my Jest environment?

Edit: I need to checkout this locally and check for differences.

---

<div class="post-metadata">

**Author:** ![mreiche](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/mreiche/32/1912_2.png) [@mreiche](https://discourse.aurelia.io/u/mreiche)\
**Post date:** [June 14, 2024, 10:29am UTC](https://discourse.aurelia.io/t/constructor-not-called-in-aurelia-2-components-tests/5454/4 "2024-06-14T10:29:06Z")

</div>

It was my outdated `jest.config.ts`.  
I took the `jest` part of `package.json` from `npx makes aurelia` and the test now works as expected.
