-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_events.test.js
54 lines (42 loc) · 2.01 KB
/
add_events.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//test events are added to the database
import { fireEvent, getByText } from '@testing-library/dom'
import '@testing-library/jest-dom/extend-expect'
import { JSDOM } from 'jsdom'
import fs from 'fs'
import path from 'path'
import { assert } from 'console' //import assert from 'assert', used to test if the event was added to the database
const html = fs.readFileSync(path.resolve(__dirname, './add_events.html'), 'utf8');
let dom
let container
describe('add_events.html', () => {
it('renders a form element', () => {
dom = new JSDOM(html) //creates a new instance of JSDOM
container = dom.window.document.body //creates a new instance of the body
expect(container.querySelector('form')).toBeInTheDocument() //checks if the form is in the document
})
// test that a button is rendered
it('renders a button element', () => {
dom = new JSDOM(html) //creates a new instance of JSDOM
container = dom.window.document.body //creates a new instance of the body
expect(container.querySelector('button')).toBeInTheDocument() //checks if the button is in the document
})
//test that the form is submitted
it('form is submitted', () => {
dom = new JSDOM(html)
container = dom.window.document.body
const form = container.querySelector('form')
const button = container.querySelector('button')
fireEvent.submit(form)
expect(button).not.toBeNull()
expect(getByText(container, 'Submit')).toBeInTheDocument()
})
// test event listener is responding to the click event
it('button is clicked', () => {
dom = new JSDOM(html)
container = dom.window.document.body
const button = container.querySelector('button')
fireEvent.click(button)
expect(button).not.toBeNull()
expect(getByText(container, 'Submit')).toBeInTheDocument()
})
})