question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Next/link makes Jest+Enzyme tests fail. — TypeError: The "url" argument must be of type string. Received type undefined

See original GitHub issue

Bug report

Every component that contains a Next Link component is throwing an error while testing it.

Everything was working fine with Next 9.1.6.

This might relate to https://github.com/zeit/next.js/issues/9951 (?).

Describe the bug

Jest+Enzyme unit test suites are failing after upgrading NextJS from 9.1.6 to 9.2.1.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. npm i
  2. jest
  3. See error: TypeError: The "url" argument must be of type string. Received type undefined

Console Screenshot

Screen Shot 2020-01-29 at 3 22 01 PM

Expected behavior

Unit tests that were passing with Next 9.1.6 should still pass after upgrading Next version.

System information

  • OS: macOS
  • Node: 12.13
  • Version of Next.js: 9.2.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
timswallingcommented, Feb 4, 2020

I had the same issue. In my case it was caused by an incomplete mock of window.location that was missing the pathname property.

2reactions
lippcommented, Feb 5, 2020

@timswalling thanks for the hint! 👍 After adding pathname to window.location fake in the jest.setup.js file , tests are working again.

// jest.setup.js
Object.defineProperty(window, 'location', {
	value: {
		pathname: '',
	},
	writable: true,
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Next/link makes Jest+Enzyme tests fail. — TypeError: The "url ...
Next/link makes Jest+Enzyme tests fail. — TypeError: The "url" argument must be of type string. Received type undefined #10328.
Read more >
axios The "url" argument must be of type string. Received type ...
You are using destructuring: await axios({ downloadUrl, responseType: "stream" }). This means, You are using downloadUrl as key, instead of ...
Read more >
The "url" argument must be of type string. Received undefined
I am receiving this error during the deployment of my express/node app using App platform. Couldn't figure what is the problem! config.json:
Read more >
Continuous integration for React applications using Jest and ...
This tutorial covers: Cloning and setting up a sample React and Redux app; Writing tests for the application; Configuring continuous integration ...
Read more >
React Router - Testing Library
In your tests, pass the history object as a whole to the Router component. Note: React Router v5 only works with History v4,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found