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

Wrong window.location after redirection #1627

Open
spamshaker opened this issue Nov 26, 2024 · 0 comments
Open

Wrong window.location after redirection #1627

spamshaker opened this issue Nov 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@spamshaker
Copy link

spamshaker commented Nov 26, 2024

Describe the bug
When you want to access the final location after redirection the location is set to initial while browser exposes the final location.

To Reproduce

npm i msw happy-dom
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import { deepEqual, strictEqual } from 'node:assert';
import { Browser } from 'happy-dom';

const handlers = [
  http.get('https://example.com/user', () => {
    return HttpResponse.redirect('https://example.com/auth');
  }),
  http.get('https://example.com/auth', () => {
    return HttpResponse.html('AUTH PAGE');
  }),
  http.get('*', (req) => {
    throw new Error('Not mocked yet' + req.request.url);
  })
];
const server = setupServer(...handlers);
server.listen();
const result = await fetch('https://example.com/user').then(async (res) => {
  return {
    status: res.status,
    content: res.headers.get('content-type')?.includes('json') ? await res.json() : await res.text()
  };
});

// Ensure MSW redirected content properly while fetch
deepEqual(result, { status: 200, content: 'AUTH PAGE' });

const browser = new Browser();
const page = browser.newPage();
await page.goto('https://example.com/user');
strictEqual(page.content, '<html><head></head><body>AUTH PAGE</body></html>');
strictEqual(page.mainFrame.window.location.href, 'https://example.com/auth');
//  ^ AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
// + actual - expected

// + 'https://example.com/user'
// - 'https://example.com/auth'

Expected behavior
this should pass

strictEqual(page.mainFrame.window.location.href, 'https://example.com/auth');

Screenshots
If applicable, add screenshots to help explain your problem.

Device:

  • OS: MacOs
  • Browser: nodejs
  • Version: 22

Additional context

@spamshaker spamshaker added the bug Something isn't working label Nov 26, 2024
@spamshaker spamshaker changed the title Wrong window.location after redirect Wrong window.location after redirection Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant