# Best way to import (or mock) a shimming module in test?

**URL:** <https://discuss.emberjs.com/t/best-way-to-import-or-mock-a-shimming-module-in-test/13013>\
**Category:** Uncategorized\
**Created:** [May 22, 2017, 4:12am UTC](https://discuss.emberjs.com/t/best-way-to-import-or-mock-a-shimming-module-in-test/13013 "2017-05-22T04:12:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nightire](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nightire/32/14788_2.png) [@nightire](https://discuss.emberjs.com/u/nightire)\
**Post date:** [May 22, 2017, 4:12am UTC](https://discuss.emberjs.com/t/best-way-to-import-or-mock-a-shimming-module-in-test/13013/1 "2017-05-22T04:12:43Z")

</div>

Here’s the situation:

1. The purpose is to write a service
2. in this service, a 3rd party library was introduced (device.js)
3. I use ember-cli-node-assets to add this tiny lib into vendor tree
4. I use `app.import` to import this tiny lib, also `app.import` a shims to wrap this lib into ES2015 module
5. `import` this shimming module in this service
6. now tests running in browser are fine
7. tests running in local CLI (macOS w/ phantomjs) are fine too (I was thought it will fails too! surprise)
8. tests running in CI (jenkins on ubuntu 16.04 w/ same version of node & yarn & phantomjs) are failed when tests cover the part involved with the 3rd party module

I known this 3rd-party lib is depends on `document` and user agent, but I think phantomjs can handle that for me, I’m also try to access global `window.device` successfully, the real problem is tests failed because of:

`undefined is not a function (evaluating '_device.default.mobile()')`

anyone knows how to actually import (or even mock this module) under this situation?
