If you're just trying to mock the http response, then a library like Sinon
might be a better approach.
There is another option, which is to override core-ajax's prototype and
change what happens inside of urlChanged. Take a look at this discussion on
twitter <https://twitter.com/polymer/status/486217597419929600> and in
particular the jsbin at the end <http://jsbin.com/wipitu/1/edit>.

On Sun, Sep 28, 2014 at 8:25 PM, <[email protected]> wrote:

> Hi everyone, Im just starting on polymer. Im trying to unit test a custom
> element that has dependencies and I would like to fake/mock these out.
> I've found Scott Miles recommendation on how to mock the core-ajax
> implementation. I thought I could follow that pattern easily but this only
> works as long as my element does not import the about to be mocked
> (core-ajax in this case) element.
> If it does import it, then when the test tries to run I get
>
> 'Uncaught NotSupportedError: Failed to execute 'registerElement' on
> 'Document': Registration failed for type 'core-ajax'. A type with that name
> is already registered.'
>
> If I could do something like document.unregister the core-ajax element and
> import it again in my test, Id be a much happier dev!!!
> Polymer is awesome but if I can not unit test it, then it presents major
> risks (at least when building an app that will need to be
> maintained/changed)
>
> How are you guys working around this? I've been digging into Polymer and
> PolymerLab elements repo and most of them lack tests. So far I;ve not found
> much reference on how to do it.
>
> Thanks for the help!
>
> Santiago
>
> Scotts' recommendation was:
>
> 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'm interested to
> hear what you find (in)convenient.
>
> 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/650f51fd-290f-458a-abb0-2a5af04e3916%40googlegroups.com
> <https://groups.google.com/d/msgid/polymer-dev/650f51fd-290f-458a-abb0-2a5af04e3916%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

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/CAJj5OwDU_Tv_1exUovUdMk9FWStsM1zoROBabtjMs5W-Ygwu1g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to