Im just starting with polymer. Im trying to unit test a custom item that has dependencies and I would like to fake / mock them. I found Scott Miles' recommendation on how to mock the core-ajax implementation. I thought I could easily follow this pattern, but this only works until my element imports the element that will mock (kernel-ajax in this case). If it imports it, then when the test tries to run, I get
'Uncaught NotSupportedError: Failed to execute' registerElement 'in' Document ': Registration error for type' core-ajax '. A type with this name is already registered. ''
If I could do something like document.unregister the core-ajax element and import it again into my test, Id would be a lot happier dev !!! The polymer is awesome, but if I cannot unit test it, then it poses serious risks (at least when creating an application that needs to be saved / modified).
How do you guys work on this? I dug repos on Polymer and PolymerLab, and most of them were flawed. So far I have not found many links on how to do this.
Thanks for the help!
Santiago
Scotts Recommendation:
Instead of importing core-ajax / core-ajax.html, create your own core-ajax element.
<polymer-element name="core-ajax" attributes="response"> <script> Polymer('core-ajax', { attached: function() { this.response = ['a', 'b', 'c']; } }); </script> </polymer-element>
Obviously, this is just an example, the actual implementation depends on the desired mocking behavior.
This is just one way to solve it, there are many others. I am interested to know what you find (at) convenient.
source share