Skip to content
Snippets Groups Projects
Commit be39fc50 authored by Viivi Nevalainen's avatar Viivi Nevalainen
Browse files

Upload New File

parent 3e3a73fb
No related branches found
No related tags found
No related merge requests found
import React from 'react'
import '@testing-library/jest-dom/extend-expect'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import BlogForm from './BlogForm'
test('<BlogForm /> calls propsfunction when blog is created', async () => {
const addBlog = jest.fn()
render(<BlogForm createBlog={addBlog} />)
const titleInput = screen.getByPlaceholderText('write title here')
const authorInput = screen.getByPlaceholderText('write author here')
const urlInput = screen.getByPlaceholderText('write url here')
await userEvent.type(titleInput, 'Test title')
await userEvent.type(authorInput, 'Test author')
await userEvent.type(urlInput, 'http://example.com')
const submitButton = screen.getByText('create')
await userEvent.click(submitButton)
expect(addBlog).toHaveBeenCalledTimes(1)
expect(addBlog).toHaveBeenCalledWith({
title: 'Test title',
author: 'Test author',
url: 'http://example.com',
likes: 0
})
})
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment