Skip to content

Commit 6374ff6

Browse files
taty2010maxcell
andauthored
Tn/add cypress (#47)
* added cypress, updated toml with cypress plugin, and created testing for the form * Update cypress/e2e/form.cy.js Co-authored-by: Prince Wilson <[email protected]> Co-authored-by: Prince Wilson <[email protected]>
1 parent 9ed752f commit 6374ff6

File tree

5 files changed

+2078
-10
lines changed

5 files changed

+2078
-10
lines changed

cypress.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const { defineConfig } = require('cypress')
2+
3+
module.exports = defineConfig({
4+
e2e: {
5+
baseUrl: "http://localhost:8888/",
6+
supportFile: false,
7+
chromeWebSecurity: false,
8+
},
9+
});

cypress/e2e/form.cy.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
describe('Testing form', () => {
2+
3+
const name = 'Testing'
4+
const email = '[email protected]'
5+
const feedback = 'Testing form using Cypress'
6+
7+
beforeEach(() => {
8+
cy.visit('/')
9+
})
10+
11+
it('check for validation message for invalid email input', () => {
12+
cy.get('[type="email"]').type('not_an_email')
13+
cy.get('[type="submit"]').click()
14+
cy.get('[type="email"]').then(($input) => {
15+
expect($input[0].validationMessage).to.eq('Please include an \'@\' in the email address. \'not_an_email\' is missing an \'@\'.')
16+
})
17+
})
18+
19+
it('check for validation message for no email input', () => {
20+
cy.get('[type="submit"]').click()
21+
cy.get('[type="email"]').then(($input) => {
22+
expect($input[0].validationMessage).to.eq('Please fill out this field.')
23+
})
24+
})
25+
26+
it('check for validation message with email and no feedback', () => {
27+
cy.get('[type="email"]').type(email)
28+
cy.get('[type="submit"]').click()
29+
cy.get('#feedback').then(($input) => {
30+
expect($input[0].validationMessage).to.eq('Please fill out this field.')
31+
})
32+
})
33+
34+
it('submitting feedback should redirect to /success', () => {
35+
cy.get('#name').type(name)
36+
cy.get('[type="email"]').type(email)
37+
cy.get('#feedback').type(feedback)
38+
cy.get('[type="submit"]').click()
39+
40+
cy.url().should('include', '/success')
41+
42+
})
43+
})

netlify.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@
1818

1919
[functions]
2020
node_bundler = "esbuild"
21+
22+
[[plugins]]
23+
package = "netlify-plugin-cypress"
24+
[plugins.inputs.postBuild]
25+
enable = true
26+
27+
[plugins.inputs]
28+
enable = false

0 commit comments

Comments
 (0)