Skip to content

Instantly share code, notes, and snippets.

@keichan34
Last active September 11, 2016 13:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keichan34/2b8e31006a8b71a277ca to your computer and use it in GitHub Desktop.
Save keichan34/2b8e31006a8b71a277ca to your computer and use it in GitHub Desktop.
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());
});
});
@zoldar
Copy link

zoldar 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