I'm trying to make use of a library (chance.js) in my Ember unit tests, but I can't seem to import it in my tests.
So far I've tried using NPM (with and without ember-browserify), Bower (played around with trying the app.import
calls in ember-cli-build.js
.
No matter what I do, I can't seem to be able to access the chance
functions/module.
Any help would be greatly appreciate. Top marks would go to anyone who can point me to an Ember project which is using chance.js
in their unit tests.
If possible in your answer, a brief explanation of which dependency management is appropriate would be very helpful. From what I've read, it seems NPM might be the go-to as the Ember project is looking to move away from Bower, see here.
Also, if anyone knows of any helpful articles (up-to-date would also be a plus), feel free to mention them in comments.
Thanks!
Edit: I believe some of the issues I am seeing are related to Chance using the 'anonymous' AMD module, which Ember's loader does not support. I played around a little more, but ended up going with the ember-faker addon as it is supported out of the box thanks to John Otander.
I'll leave this question here in hopes of someone posting a wonderful answer which clarifies things :).
Ember CLI now supports Anonymous AMD modules. In your ember-cli-build.js
file, use app.import()
with the AMD transformation, giving the anonymous module a name like this:
app.import('bower_components/chance/dist/chance.min.js', {
using: [
{ transformation: 'amd', as: 'chance' }
]
});
Then, you can import it throughout your app and tests like this:
import chance from 'chance';