Tests Are Code, Too!

Aaron Greenwald

Survey
00 / Preface
Testing Pyramid
Jest
Jasmine
Mocha
Protractor
Puppeteer
...etc
01 / Why We Care
maybe we don't
(so don't get too hung up on this)
but we do care
Easier maintenance
Easier readability
...etc
But wait...there's more
02 / Why We Test
Bug Prevention
Bug Remediation
Velocity
Confidence
Design (TDD)
Documentation
RDD
Satisfaction
03 / Why We Care (pt 2)
so that they last
so that they explain
Bug Prevention
Bug Remediation
Velocity
Confidence
Design (TDD)
Documentation
RDD
Satisfaction
Bug Prevention
Bug Remediation
Velocity
Confidence
Design (TDD)
Documentation
RDD
Satisfaction
Bug Prevention
Bug Remediation
Velocity
Confidence
Design (TDD)
Documentation
RDD
Satisfaction
Bug Prevention
Bug Remediation
Velocity
Confidence
Design (TDD)
Documentation
RDD
Satisfaction
But it's hard
We're in a rush
We don't know how
04 / A Better Way
Read like prose
Keep them SHORT
Hide the mess
given / when / then

it('should choose the best dev stack given the audience', () => {
    givenAudience('ReactILMeetup');

    const choice = getBestFedStack();

    expect(choice).toContain('React');
});
                    
builders

it('should support creating adding todos to a list', () => {
    const todo = {
        id: 'todo-item-id',
        title: 'some title'
    };

    todoList.add(todo);

    expect(todoList.get('todo-item-id')).toBe(todo);
});
                

it('should support creating adding todos to a list', () => {
    const todo = new TodoBuilder()
        .withId('todo-item-id')
        .build();

    todoList.add(todo);

    expect(todoList.get('todo-item-id')).toBe(todo);
});
                

it('should support deleting attachments from a todo', () => {
    const todo = new TodoBuilder()
        .withAttachments([
            new AttachmentBuilder().build()
        ])
        .build();

    const updatedTodo = todo.deleteAttachments();

    expect(updatedTodo.attachments).toBe(null);
});
                

const todo = new TodoBuilder()
    .withAttachments([
        new AttachmentBuilder()
            .withId('attachment-0-id')
            .build(),
        new AttachmentBuilder()
            .withId('attachment-1-id')
            .build()
    ])
    .build();
                
aFooBar()

function aTodoWithAttachments(length = 0) {
    return new TodoBuilder()
        .withAttachments([
            ...new Array(length).fill(0).map((_, i) =>
                new AttachmentBuilder()
                    .withId(`attachment-${i}-id`)
                    .build()
            )
        ])
        .build();
}
                

const todo = aTodoWithAttachments(3);

todo.deleteFirstAttachment();

expect(todo.attachments.length).toBe(2);
                
drivers

it('should open the new todo window on button press', () => {
    todoListDriver.loadPage();

    todoListDriver.when.newTodoButtonClicked();

    expect(driver.get.newTodoModal()).toBeVisible();
});
                

class TodoListDriver extends PageDriver {
    loadPage() {
        this.driver.navigateTo('/todos');
    }

    when = {
        newTodoButtonClicked () {
            $('#new-todo').click();
        }
    }

    get = {
        newTodoModal () {
            return $('#new-todo');
        }
    }
}
                
05 / No Code
The cleanest code is the code that doesn't exist...
testim.io
Same same...but different
06 / Before You Go
Be a Champion
Accept Your Responsibility
Clean Your Tests
#clean_your_tests
        
it('should render footer when loading', () => {
  givenAppInLoadingState();
  expect(footer).toBeVisible();
});
        
    
E2E
Integration
Unit