I'm kinda stuck there... Unit testing a component with mocha is pretty easy. But as soon as there are dependencies involved it gets kinda messy. I can't just install the other components with npm, and I can't include the build.js in mocha.
So, am I forced to write the tests in the browser and include the build?
EDIT: And I'm aware that unit testing should happen without the other modules, but I can't stub them because my component already fails when trying to require another one.
yeah that part is not super easy right now, but since they're designed for the browser they should be tested in browser(s) or phantomjs etc. I do use mocha and node to test a few of the more simple ones but that breaks down with deps like you found. I dont think this is really a component specific issue, it's more or less the same issue any non-node environment faces
in the future I'd love to normalize all component testing with a test-swarm type of tool, but that's definitely not on the immediate list of things to do
this is still a pretty big pain for me. our current workaround is to change the standard build from this:
@component build --dev
to use the standalone flag:
@component build --standalone build --out ./build --name build
and then require build.js as so that i can do mocha testing in the terminal. but this breaks down when you want to include one of your dependency components (or any other component) for use in your testing suite.
how can we unbreak require-ing components in our testing suites? two ideas so far:
am i missing something obvious or is this a big problem for testing with component (when your component isn't a tiny piece of code, but has dependencies).
Unfortunately webpack doesn't support components yet, but maybe in the next few weeks.
Now he has written a plugin for components ^^.
Sorry, I just realized that it doesn't really answer your question. But it makes testing in the browser almost like testing in the terminal.
yeah, it looks like testing in the browser w/mocha is the way to go. if your tests fail at least chrome dev tools can help you debug.... would be nice to have testing in the terminal though. thanks!
I have a workflow that lets me run tests in phantomjs via grunt. I use grunt to watch my index.js and build it automatically. I then use mocha in browser-mode, including the build.js file, and exposing the component via the require('name/repo). I can then run my tests via grunt mocha. It works quite well. You can see it w/ a (more extensive) component I've been working on recently: https://github.com/bmcmahen/cast