Last active
July 11, 2017 17:38
-
-
Save joelgriffith/e5e0ee00c162cd7f3aa044590321756d to your computer and use it in GitHub Desktop.
Full test suite with just Chrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Chrome } = require('navalia'); | |
describe('My Page', () => { | |
let chrome = {}; | |
beforeEach(() => { | |
chrome = new Chrome(); | |
}); | |
afterEach(() => { | |
return chrome.done(); | |
}); | |
it('should have a username input', () => { | |
return chrome.goto('http://localhost:3000/') | |
.then(() => chrome.exists('[data-test="username"]')) | |
.then((exists) => expect(exists).toEqual(true)); | |
}); | |
it('should have a submit button', () => { | |
return chrome.goto('http://localhost:3000/') | |
.then(() => chrome.exists('[data-test="password"]')) | |
.then((exists) => expect(exists).toEqual(true)); | |
}); | |
it('should have a submit button', () => { | |
return chrome.goto('http://localhost:3000/') | |
.then(() => chrome.exists('[data-test="submit"]')) | |
.then((exists) => expect(exists).toEqual(true)); | |
}); | |
it('should show an error if no username is filled out', () => { | |
return chrome.goto('http://localhost:3000/') | |
.then(() => chrome.click('[data-test="submit"]')) | |
.then(() => chrome.html('[data-test="error"]')) | |
.then((html) => expect(html).toContain('Username is required')); | |
}); | |
it('should show a password error if a username is filled but no password', () => { | |
return chrome.goto('http://localhost:3000/') | |
.then(() => chrome.type('[data-test="username"]', 'joel@joelgriffith.net')) | |
.then(() => chrome.click('[data-test="submit"]')) | |
.then(() => chrome.html('[data-test="error"]')) | |
.then((html) => expect(html).toContain('Password is required')); | |
}); | |
it('dismisses username errors', () => { | |
return chrome.goto('http://localhost:3000/') | |
.then(() => chrome.click('[data-test="submit"]')) | |
.then(() => chrome.click('[data-test="error"] button')) | |
.then(() => chrome.exists('[data-test="error"]')) | |
.then((errorPersists) => expect(errorPersists).toEqual(false)); | |
}); | |
it('dismisses password errors', () => { | |
return chrome.goto('http://localhost:3000/') | |
.then(() => chrome.type('[data-test="username"]', 'joel@joelgriffith.net')) | |
.then(() => chrome.click('[data-test="submit"]')) | |
.then(() => chrome.click('[data-test="error"] button')) | |
.then(() => chrome.exists('[data-test="error"]')) | |
.then((errorPersists) => expect(errorPersists).toEqual(false)); | |
}); | |
it('should show no errors if both username and password are filled out', () => { | |
return chrome.goto('http://localhost:3000/') | |
.then(() => chrome.type('[data-test="username"]', 'joel@joelgriffith.net')) | |
.then(() => chrome.type('[data-test="password"]', '1234foobarbaz')) | |
.then(() => chrome.click('[data-test="submit"]')) | |
.then(() => chrome.exists('[data-test="error"]')) | |
.then((errorExists) => expect(errorExists).toEqual(false)); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment