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

document URL parsing #2453

Closed
PauloASilva opened this issue Dec 27, 2016 · 8 comments
Closed

document URL parsing #2453

PauloASilva opened this issue Dec 27, 2016 · 8 comments

Comments

@PauloASilva
Copy link

Do you want to request a feature or report a bug?
bug

What is the current behavior?

function parseURL (url) {
    var parser = document.createElement('a');

    parser.setAttribute('href', url);

    return {
        protocol: parser.protocol,
        username: parser.username,
        password: parser.password,
        host: parser.host,
        hostname: parser.hostname,
        port: parser.port,
        pathname: parser.pathname,
        search: parser.search,
        hash: parser.hash
    };
}
Object.defineProperty(window.location, 'href', {
    writable: true,
    value: 'http://github.com'
});

parseURL('//somehost.com');
// {
//     "hash": "", 
//     "host": "", 
//     "hostname": "", 
//     "password": "", 
//     "pathname": "", 
//     "port": "", 
//     "protocol": ":", 
//     "search": "", 
//     "username": ""
// }

This is the Firefox and Google Chrome behavior when the source code runs on a page whose document.location is about:blank what is not expected as the window.location.href property is defined by (Issue#890)

Object.defineProperty(window.location, 'href', {
    writable: true,
    value: 'http://github.com'
});

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

What is the expected behavior?

parseURL('//somehost.com');
// {
//     protocol: "https:",
//     username: "",
//     password: "",
//     host: "somehost.com",
//     hostname: "somehost.com",
//     port: "",
//     pathname: "/",
//     search: "",
//     hash: ""
// }

This is the Firefox and Google Chrome behavior when the source code run on a page whose document.location is other than about:blank.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

  • Jest: v16.0.2
  • Node: v5.1.0
  • NPM: 2.14.12
  • OS: Ubuntu 16.04.1 LTS
@thymikee
Copy link
Collaborator

I'm not sure if we can do anything about that. @cpojer what do you think?

@PauloASilva
Copy link
Author

@thymikee I would be glad to help you further but I had no time no go deeper on debugging.
As soon as I am able to take some spare time I will do it and I will let you know.

Jest uses jsdom, right?
Isn't this a jsdom issue?

@thymikee
Copy link
Collaborator

Yes, Jest uses jsdom and what I'm quite sure, this is not a bug in Jest – this can be a lack of feature/API flexibility though.
Although it may be a bug in jsdom lib, so please file an issue there and we'll see how it goes. Closing this for now.

@thymikee
Copy link
Collaborator

But happy to discuss it of course!

@PauloASilva
Copy link
Author

I was digging1 and setting the testURL jest property on `package.json (doc) solves the issue.

I think that it would be nice to be able to manipulate the jsdom environment instance everywhere, so that I was able to call the jsdom.changeURL() method. Do I have access to it on global scope?

Regards,
Paulo A. Silva

@thymikee
Copy link
Collaborator

Glad you worked this out!
Currently we're not exposing jsdom to environment, so you don't have access to it. Happy to review the PR if you're willing to work on this, as long as it doesn't introduce breaking changes :).
I'll create a new issue just for that.

@PauloASilva
Copy link
Author

i @thymikee thanks for you quick feedback.

Let's work on feature request.
I think exposing jsdom would make sense, but I am not sure about the consequences to the jest philosophy.

I am moving to the new issue

Thanks
Paulo A. Silva

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2021
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

2 participants