Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: window is not defined in Protractor / E2E Tests #405

Open
tobiasschweizer opened this issue Jul 17, 2020 · 1 comment
Open

Comments

@tobiasschweizer
Copy link

tobiasschweizer commented Jul 17, 2020

I am developing an Angular library that has an indirect dependency on jsonld.
When I run my E2E tests that import elements of my Angular library I get:

E/launcher - Error: ReferenceError: window is not defined
at Object. (/.../node_modules/jsonld/dist/jsonld.js:10:4)

I found out that jsonld/dist/jsonld.js (distributed code: https://www.npmjs.com/package/jsonld/v/1.8.1) uses window: (window, function() { (line 10).

My understanding is that protractor is not aware of DOM objects that are normally available in client-side JS, so I added the following code in protractor.conf.js:

global['window'] = {
    addEventListener: () => {}
};

Details can be found here: dasch-swiss/dsp-ui-lib#124

Has anyone faced a similar issue with protractor and jsonld? If yes, how was it solved?

@tobiasschweizer
Copy link
Author

tobiasschweizer commented Jul 17, 2020

I am still using this workaround to import jsonld: const jsonld = require('jsonld/dist/jsonld.js');

I tried to change this to import * as jsonld from 'jsonld'; but then I get

jsonld.js:1034 Uncaught ReferenceError: global is not defined
at wrapper (jsonld.js:1034)
at Object../node_modules/jsonld/lib/jsonld.js (jsonld.js:1073)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant