# Aurelia Unit Testing --\> Expect Error

**URL:** <https://discourse.aurelia.io/t/aurelia-unit-testing-expect-error/1199>\
**Category:** Help Requests\
**Created:** [May 9, 2018, 1:34pm UTC](https://discourse.aurelia.io/t/aurelia-unit-testing-expect-error/1199 "2018-05-09T13:34:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SNO](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sno/32/650_2.png) [@SNO](https://discourse.aurelia.io/u/SNO)\
**Post date:** [May 9, 2018, 1:34pm UTC](https://discourse.aurelia.io/t/aurelia-unit-testing-expect-error/1199/1 "2018-05-09T13:34:14Z")

</div>

Hi,

currently I’m trying to create a unit test case that expects a thrown exception:

```auto
it('should throw an error because of invalid base url', () => {
        let errorApiConfiguration = new TestApiConfigurationDev();
        errorApiConfiguration.baseRoute = 'localhost:9000';
        expect(this.apiService.setApiConfigurations([errorApiConfiguration])).toThrowError(Error);
  });

```

the respective `setApiConfigurations` method throws the exception:

```auto
public setApiConfigurations(object: Object[]) {
     throw new Error('test');
}

```

With this setup the test run fail:

```auto
ApiService › should throw an error because of invalid base url

    test

      207 | public setApiConfigurations(object: Object[]) {
    > 208 | throw new Error('test'); 
      209 | }   

```

Does anyone know what I’m doing wrong here respectively how to get that test working?

---

<div class="post-metadata">

**Author:** ![zewa666](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/zewa666/32/19_2.png) [@zewa666](https://discourse.aurelia.io/u/zewa666)\
**Post date:** [May 10, 2018, 7:38am UTC](https://discourse.aurelia.io/t/aurelia-unit-testing-expect-error/1199/2 "2018-05-10T07:38:51Z")

</div>

You have to change the assertion to execute an function which in turn throws.

```auto
expect(() => this.apiService.setApiConfigurations([errorApiConfiguration])).toThrowError(Error);

```
