Skip to content

Instantly share code, notes, and snippets.

View joelgriffith's full-sized avatar
💻
Turns out I'm really good at computers

Joel Griffith joelgriffith

💻
Turns out I'm really good at computers
View GitHub Profile
@joelgriffith
joelgriffith / jest-image-snapshot.js
Created July 20, 2017 15:23
Assertions using jest-image-snapshots!
it('should not have visual regressions', () => {
...do something to generate an image...
expect(image).toMatchImageSnapshot();
});
@joelgriffith
joelgriffith / visual-regression.js
Created July 19, 2017 22:58
Visual Regression Testing in Navali
const { Chrome } = require('navalia');
const { toMatchImageSnapshot } = require('jest-image-snapshot');
expect.extend({ toMatchImageSnapshot });
describe('Visual Regressions', () => {
let chrome = null;
beforeEach(() => {
chrome = new Chrome();
@joelgriffith
joelgriffith / navalia-suite.js
Created July 11, 2017 18:14
Test suite with Navalia and parallelization
const { Navalia } = require('navalia');
const navalia = new Navalia();
describe('My Page', () => {
afterAll(() => {
return navalia.kill();
});
it.concurrent('should have a username input', () => {
@joelgriffith
joelgriffith / empty-username-navalia.js
Created July 11, 2017 17:55
Validating username error with Navalia LB
// Register the work against a Navalia instance
// returning so the test can signal completetion:
it('should have a username input', () => {
return navalia.run((chrome) => chrome.goto('http://localhost:3000/')
.then(() => chrome.exists('[data-test="username"]'))
.then((exists) => expect(exists).toEqual(true)));
});
@joelgriffith
joelgriffith / full-suite-chrome.js
Last active July 11, 2017 17:38
Full test suite with just Chrome
const { Chrome } = require('navalia');
describe('My Page', () => {
let chrome = {};
beforeEach(() => {
chrome = new Chrome();
});
afterEach(() => {
@joelgriffith
joelgriffith / composable-test.js
Created July 11, 2017 17:24
Composing a user interaction with further assertions
// :missingUsername visits a page and immediately clicks submit
// without entering the user's name. It returns the chrome instance
// so you can invoke further actions or assertions!
const missingUsername = (chrome) =>
chrome.goto('http://localhost:3000/')
.then(() => chrome.click('[data-test="submit"]'));
// Consume the prior action and assert further behavior
it('should allow users to dismiss errors', () => {
return missingUsername(chrome)
@joelgriffith
joelgriffith / composoable-login.js
Created July 11, 2017 17:20
Abstracting User Interactions in Navalia
// :missingUsername visits a page and immediately clicks submit
// without entering the user's name. It returns the chrome instance
// so you can invoke further actions or assertions!
const missingUsername = (chrome) =>
chrome.goto('http://localhost:3000/')
.then(() => chrome.click('[data-test="submit"]'));
@joelgriffith
joelgriffith / empty-username.js
Created July 11, 2017 17:07
Blank username assertion
// Goto a page, click a button, expect a message
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'));
});
@joelgriffith
joelgriffith / react.spec.js
Last active July 11, 2017 16:58
Setup of Navalia E2E Test
const { Chrome } = require('navalia');
const pageUrl = 'http://localhost:3000/';
describe('My Page', () => {
let chrome = {};
// Setup a clean instance for each test
beforeEach(() => {
chrome = new Chrome();
});
@joelgriffith
joelgriffith / Login-Page.js
Created July 11, 2017 16:48
Simple React login-page for testing
import React, { Component } from 'react';
import './App.css';
class LoginPage extends Component {
constructor() {
super();
this.state = {
username: '',
password: '',
error: '',