Zone.js does not work with Zombie/jsdom
I'm trying to get an Angular2 app running in Zombie, and seeing the following error (presumably from jsdom):
TypeError: Cannot redefine property: onclick at Function.defineProperty (native) at canPatchViaPropertyDescriptor (http://localhost:8080/app.js:35698:12) at Object.apply (http://localhost:8080/app.js:35677:9) at Object.apply (http://localhost:8080/app.js:35288:29) at http://localhost:8080/app.js:35165:16 at linkDynamicModule (http://localhost:8080/app.js:262:32) at getModule (http://localhost:8080/app.js:231:9) at http://localhost:8080/app.js:266:16 at http://localhost:8080/app.js:35147:20 at linkDynamicModule (http://localhost:8080/app.js:262:32) in http://localhost:8080/
ORIGINALY FILED AS: https://github.com/angular/angular/issues/3584
/cc @danhalliday
Looks like we need to wrap that check in a try/catch for environments that make that property non-configurable.
I might be able to spend some time looking at a PR, as it'd be really cool to try out Zombie with Angular 2. When you say try/catch it, do you mean just fail more gracefully, or do you think it would be possible for Zone to work without redefining onclick?
What's strange is that looking at the code, it seems Zone already handles non-configurable properties (here: https://github.com/angular/zone.js/blob/v0.5.8/lib/patch/property-descriptor.js#L36 it looks like patchViaCapturingAllTheEvents() should be called).
I've debugged my app code and tracked down the actual stack trace for the error:
Object.defineProperty(obj, prop, desc);
// https://github.com/angular/zone.js/blob/master/lib/utils.js#L73
patchProperty(obj, eventName);
// https://github.com/angular/zone.js/blob/master/lib/utils.js#L88
utils.patchProperties(HTMLElement.prototype, onEventNames);
// https://github.com/angular/zone.js/blob/master/lib/patch/property-descriptor.js#L21
propertyDescriptorPatch.apply();
// https://github.com/angular/zone.js/blob/master/lib/patch/browser.js#L34
browserPatch.apply();
// https://github.com/angular/zone.js/blob/master/lib/browser/zone.js#L13
Turns out canPatchViaPropertyDescriptor() returns true.
I was getting this error when trying to run Angular2 with [email protected]. However after upgrading to [email protected] and the latest version of Angular2 and it's dependencies I no longer get this error and I'm able to run Angular2 in jsdom.
@natewallace does this still work for you? [email protected] is throwing this issue for me still with angular2
@bvkimball Yes, it still works for me with [email protected], [email protected], and [email protected].
With [email protected] and [email protected] [email protected] fails for me.
Is there any momentum on this? [email protected], @angular/*@2.1.4 and [email protected] fails when running tests via jest and I'd like to avoid rewriting my existing suite if at all possible
Would love to have A PR for this.
I tried to write a patch for jsdom some times ago and it could work but I don't have the skills to make a real PR of it: https://github.com/tmpvar/jsdom/pull/1610
Is there a repo to reproduce?
Closing this ticket due to the lack of repro.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.