I just spent some time on this and here's what I have to show: https://github.com/robdodson/polymer-karma-test
I think the duplicate error was caused by how you were including the components directory in karma.conf.js. I saw two entries for components, so I reduced it to one and set included to false. In each suite I have a before block where I setup the link tag for my element and listen for its load event before jumping into the individual tests. Also take a look at test/karma-loader.js where I load polymer.html and listen for the polymer-ready event before kicking off mocha. So, you can try to use this approach to see how far you get with it. The nice part about the iframe work around is that you don't have to manually manage the link elements yourself and it reduces possible prototype pollution issues but if you prefer this style that's cool too :) Keep in mind, Karma was invented in an era before Web Components even existed and making testing web components easy is not one of their design goals. At present, there isn't a really great tool for testing Web Components because they're so new. We hope that story changes in the future, but it will take time for us to get there. Hope this helps! On Tuesday, May 20, 2014 7:59:37 AM UTC-7, keithamus wrote: > > Seems a shame to have to plug (read: hack) around Karma, when the default > (read: easier to set up) usage gets 99% of the way there. Not to balk at > your efforts at all - I just think it seems like tackling this problem > seems preferable to having to inject iframes with custom scripts. > > On Tuesday, 20 May 2014 15:47:49 UTC+1, Rob Dodson wrote: >> >> I know the Polymer team uses a plugin they wrote for Karma to run tests >> in iframes. You can check it out here: >> https://github.com/Polymer/core-tests/tree/master/tests >> >> We haven't written a ton of guidance around it (though I believe Addy is >> working on an article) but the tools folder in that repo might be enough to >> get you started. Maybe give it a shot, see how far you get, and we can keep >> this thread going to work through any issues. >> >> On Tuesday, May 20, 2014 7:37:29 AM UTC-7, keithamus wrote: >>> >>> I've set up a reduced test case on >>> Github<https://github.com/keithamus/polymer-karma-test>to demonstrate the >>> problem I'm having. >>> >>> Essentially, Karma <http://karma-runner.github.io/> isn't working with >>> Polymer - during running of the tests, Polymer complains about duplicate >>> elements being registered, however, in Karma's debug mode, and in fact >>> outside of the test environment, the polymer elements work fine. >>> >>> I realise that this sounds pretty much like a Karma bug, but this seems >>> like a good place to get the ball rolling at least. >>> >>> The error from Polymer is as follows: >>> >>> Error: DuplicateDefinitionError: a type with name 'a-element' is already >>> registered >>> at >>> /Users/keith/Projects/polymer-karma-test/main/bower_components/platform/platform.js:15 >>> >>> >>> Feel free to pull the repo and have a play >>> >> Follow Polymer on Google+: plus.google.com/107187849809354688692 --- You received this message because you are subscribed to the Google Groups "Polymer" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/76f2e705-82fb-4563-9898-c28228f9a891%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
