Skip to content

why is my test not working? #144

Answered by alexclaes
PhilipZi asked this question in Web
Discussion options

You must be logged in to vote

The test breaks because the Next.js router is not available in the jest tests. You need to mock it.

Additionally you are nesting a button inside an a element, which is incorrect. It should either be a simple link (a element) or a button with additional functionality - which is your case. You can use useRouter to switch between pages.

You component should look like this:

	const router = useRouter();
	const changeToFalse = useStore(state => state.changeToFalse);

	function onButtonClick() {
		changeToFalse();
		router.push('/countdown');
	}

	return (
		<StyledButton
			data-testid="countdownbutton"
			variant="countdownButton"
			onClick={onButtonClick}
		>
			<Icon variant="play" size="80px"

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by PhilipZi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Web
Labels
None yet
2 participants