Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Headers is not defined #1185

Open
ozyman42 opened this issue Dec 28, 2018 · 5 comments
Open

Headers is not defined #1185

ozyman42 opened this issue Dec 28, 2018 · 5 comments

Comments

@ozyman42
Copy link

I instruct Zombie to visit a page which has the following code:

fetch('http://localhost:8000/', {
    body: body,
    method: 'post',
    headers: new Headers({ 'Content-Type': 'text/plain' })
}).then(function (res) {return true; });

Then I get an error that Headers is not defined, so the script within the simulated headless browser does not continue because it does not recognize Headers. Do I need to add some option to Zombie so it recognizes the entire standard JS Fetch API?

@assaf
Copy link
Owner

assaf commented Dec 28, 2018

The headers property is a JavaScript object with name/value pairs.

Sent with GitHawk

@ozyman42
Copy link
Author

@edclement
Copy link

You're running within the context of node, not the browser. You can polyfill the Headers class from the browser: https://www.npmjs.com/package/fetch-headers

You're better off just using a vanilla object though...

@ozyman42
Copy link
Author

ozyman42 commented Jan 13, 2019

If the goal of Zombie.js is to create a headless browser environment for

full-stack testing

then code that relies on browser APIs should be supported, thus Zombie.js should be polyfilling the entire Fetch API.

If Zombie.js does not plan to support standardized APIs available in most browsers, then it should consider changing its stated goals or maybe documenting which APIs it does not plan on supporting.

@ozyman42
Copy link
Author

I'd be more than happy to submit a PR that adds the polyfills.

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

No branches or pull requests

3 participants