Skip to content

Instantly share code, notes, and snippets.

@keichan34 keichan34/.babelrc
Last active Sep 11, 2016

What would you like to do?
Sample Phoenix + Brunch (Babel) + Mocha test setup for unit tests
"presets": ["es2015"]

No changes to brunch-config.js (if you're already using Babel, which I think is the default)

The directory I put all my JS unit tests are in test/js (you can set this path on line 18 of package.json)

I wasn't able to put files in subdirectories in this gist, so the files that belong in other directories are clearly marked so in a comment on the first line.

"repository": {},
"dependencies": {
"babel-brunch": "^6.0.0",
"babel-core": "^6.0.0",
"brunch": "^2.1.1",
"javascript-brunch": ">= 1.0 < 1.8",
"phoenix": "file:deps/phoenix",
"phoenix_html": "file:deps/phoenix_html",
"uglify-js-brunch": ">= 1.0 < 1.8"
"devDependencies": {
"babel-preset-es2015": "^6.5.0",
"babel-register": "^6.5.1",
"mocha": "^2.4.5"
"scripts": {
"test": "mocha --compilers js:babel-register test/js/**/*.js"
// This file lives in `web/static/js/something.js`
export default function() {
return "something";
// This file lives in `test/js/something_test.js`
import assert from 'assert';
import something from '../../web/static/js/something'
describe('something()', function() {
it('does something', function () {
assert.equal("something", something());

This comment has been minimized.

Copy link

commented Feb 11, 2016

It works like charm. The missing part for me was needlessly pointing to the root of js static files instead of test directory itself. Again, thank you @keichan34 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.