assaf / zombie

Insanely fast, full-stack, headless browser testing using node.js
http://zombie.js.org/
MIT License
5.65k stars 518 forks source link

Headers is not defined #1185

Open ozyman42 opened 5 years ago

ozyman42 commented 5 years ago

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 commented 5 years ago

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

Sent with GitHawk

ozyman42 commented 5 years ago

https://developer.mozilla.org/en-US/docs/Web/API/Headers/Headers

edclement commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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