Skip to content

Instantly share code, notes, and snippets.

@tkdn
Created August 13, 2018 08:34
Show Gist options
  • Save tkdn/32f24fc7bcb55964504df8a60dc35e4b to your computer and use it in GitHub Desktop.
Save tkdn/32f24fc7bcb55964504df8a60dc35e4b to your computer and use it in GitHub Desktop.
Next.js' `nextjs-dynamic-routes` unit-test
import { Index } from '@Components/pages'
import * as React from 'react'
import { cleanup, render } from 'react-testing-library'
jest.mock('../../../routes', () => {
const React = require('react')
return {
Link: ({ children }) => {
return <div>{children}</div>
}
}
})
afterEach(cleanup)
describe('@Components/pages/Index', () => {
const envProps = 'test'
const storiesProps = [
{
id: 1,
title: 'test title.',
by: 'test_author',
url: 'http://test.com/',
score: 1
}
]
const { getByTestId } = render(<Index env={envProps} stories={storiesProps} />)
test('render with props.', () => {
expect(getByTestId('env').textContent).toBe('test')
expect(getByTestId('url-title-1').textContent).toBe('test title.')
expect(getByTestId('url-title-1').href).toBe('http://test.com/')
expect(getByTestId('by-score-1').textContent).toBe('By test_author | 1 points')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment