# How to access component's view model in unit tests

**URL:** <https://discourse.aurelia.io/t/how-to-access-components-view-model-in-unit-tests/1804>\
**Category:** Help Requests\
**Created:** [October 24, 2018, 6:00pm UTC](https://discourse.aurelia.io/t/how-to-access-components-view-model-in-unit-tests/1804 "2018-10-24T18:00:17Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Sayan751](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/sayan751/32/1861_2.png) [@Sayan751](https://discourse.aurelia.io/u/Sayan751)\
**Post date:** [October 25, 2018, 9:30am UTC](https://discourse.aurelia.io/t/how-to-access-components-view-model-in-unit-tests/1804/2 "2018-10-25T09:30:59Z")

</div>

In my experience, the view-model of the component depends on how you are staging your component and view.

```auto
StageComponent.withResources("path/to/MyComp").inView("<my-comp></my-comp>")

```

Make sure you are doing that correctly, or you component is at the specified resource path. If you are using Webpack, you need to setup the testing environment correctly. If you are using Jasmine+Karma+Webpack, you may check this out: [Aurelia-Testing with Jasmine/Karma Fails](https://discourse.aurelia.io/t/aurelia-testing-with-jasmine-karma-fails/1629/10?u=sayan751) for more info on the setup. Basically, if you are using Webpack, you need to make sure the your component under test included in the bundle (easiest would be to put the component root path to module, in Webpack config).

Once the setup is done correctly, and the specified resource is available under the said path, the `component.viewModel` should be available after the `create(bootstrap)`, irrespective of whether it is `manuallyHandleLifecycle` or not.

Hope this helps.

---

_[View the full topic](https://discourse.aurelia.io/t/how-to-access-components-view-model-in-unit-tests/1804)._
