angular icon indicating copy to clipboard operation
angular copied to clipboard

Zone.js does not work with Zombie/jsdom

Open mhevery opened this issue 11 years ago • 15 comments

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

mhevery avatar Aug 19 '15 23:08 mhevery

/cc @danhalliday

mhevery avatar Aug 19 '15 23:08 mhevery

Looks like we need to wrap that check in a try/catch for environments that make that property non-configurable.

btford avatar Aug 21 '15 19:08 btford

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?

danhalliday avatar Oct 10 '15 09:10 danhalliday

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).

danhalliday avatar Oct 10 '15 10:10 danhalliday

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.

danhalliday avatar Oct 10 '15 20:10 danhalliday

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 avatar Feb 23 '16 16:02 natewallace

@natewallace does this still work for you? [email protected] is throwing this issue for me still with angular2

bvkimball avatar May 05 '16 18:05 bvkimball

@bvkimball Yes, it still works for me with [email protected], [email protected], and [email protected].

natewallace avatar May 05 '16 19:05 natewallace

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

berwyn avatar Dec 14 '16 17:12 berwyn

Would love to have A PR for this.

mhevery avatar Dec 14 '16 21:12 mhevery

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

Swiip avatar Dec 15 '16 16:12 Swiip

Is there a repo to reproduce?

JiaLiPassion avatar Dec 17 '16 18:12 JiaLiPassion

Closing this ticket due to the lack of repro.

AndrewKushnir avatar Jan 12 '21 19:01 AndrewKushnir

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.