Presented at Web Unleashed 2017. More info at www.fitc.ca/webu
Presented by Haris Mahmood, Shopify
Overview
As front-end developers become more and more capable of building web applications, the value of testing front-end code is now more valuable than ever. Unfortunately, the testing ecosystem can be confusing, and daunting to those just getting started with the vast number of libraries and testing frameworks offering various tools and capabilities.
This talk aims to navigate the world of testing front-end code, and provide steps for front-end developers to incorporate testing into their work and projects quickly and with ease!
Objective
Provide an introduction and overview of the world of testing for front-end development, and tips and steps to get started today.
Target Audience
Front-end developers with no or little experience with testing.
Five Things Audience Members Will Learn
Understanding on why testing is important
What options exist for testing today
What type of tests are best for what scenario
How to assess what frameworks and libraries to use
Steps on getting started with testing
106. function listMovies(list) {
return list.reduce((acc, item) => {
return `${acc} ${item.name} at ${item.showTime} has $
{item.ticketsRemaining} tickets left n`;
}, '');
}
107. function listMovies(list) {
return list.reduce((acc, item) => {
return `${acc} ${item.name} at ${item.showTime} has $
{item.ticketsRemaining} tickets left n`;
}, '');
}
Jurassic World 2 at 7:00pm has 47 tickets left
Star Wars: The Last Jedi at 10:00pm has 22 tickets left
134. it('should return true when tickets are available', () => {
const testMovie = {
ticketsRemaining: 27,
};
const result = app.ticketsLeft(testMovie);
const expected = true;
expect(result).toEqual(expected);
});
135.
136.
137. function listMovies(list) {
return list.reduce((acc, item) => {
return `${acc} ${item.name} at ${item.showTime} has $
{item.ticketsRemaining} tickets left n`;
}, '');
}
138. describe('listMovies', () => {
it('should list movies, showtimes and tickets', () => {
var list = [
{
name: 'Jurassic World 2’, showTime: ‘7:00pm', ticketsRemaining: 47,
},
{
name: 'Star Wars: The Last Jedi’, showTime: ’10:00pm', ticketsRemaining: 22,
}
];
const result = app.listMovies(list);
const expected = 'Jurassic World 2 at 7:00pm has 47 tickets left nStar Wars:
The Last Jedi at 10:00pm has 22 tickets left n';
expect(result).toEqual(expected);
});
});
139.
140. Difference:
- Expected
+ Received
- Jurassic World 2 at 7:00pm has 47 tickets left
- Star Wars: The Last Jedi at 10:00pm has 22 tickets left
+ Jurassic World 2 at 7:00pm has 47 tickets left
+ Star Wars: The Last Jedi at 10:00pm has 22 tickets left
141. Difference:
- Expected
+ Received
- Jurassic World 2 at 7:00pm has 47 tickets left
- Star Wars: The Last Jedi at 10:00pm has 22 tickets left
+ Jurassic World 2 at 7:00pm has 47 tickets left
+ Star Wars: The Last Jedi at 10:00pm has 22 tickets left
142. function listMovies(list) {
return list.reduce((acc, item) => {
return `${acc} ${item.name} at ${item.showTime} has $
{item.ticketsRemaining} tickets left n`;
}, '');
}
143. function listMovies(list) {
return list.reduce((acc, item) => {
return `${acc}${item.name} at ${item.showTime} has $
{item.ticketsRemaining} tickets left n`;
}, '');
}
144.
145. describe('addMovieToList', () => {
it('adds a movie to the movie list', () => {
const list = [
{ name: 'Jurassic World 2’, showTime: ‘7:00pm', ticketsRemaining: 47 }
];
const results = app.addMovieToList(list, 'Thor', '4:30pm');
const expected = [
{ name: 'Jurassic World 2’, showTime: ‘7:00pm’, ticketsRemaining: 47 },
{ name: ‘Thor', showTime: ‘4:30pm', ticketsRemaining: 100 }
];
expect(results).toBe(expected);
});
});
148. Compared values have no visual difference. Looks like you
wanted to test for object/array equality with strict `toBe`
matcher. You probably need to use `toEqual` instead.
149. describe('addMovieToList', () => {
it('adds a movie to the movie list', () => {
const list = [
{ name: 'Jurassic World 2’, showTime: ‘7:00pm', ticketsRemaining: 47 }
];
const results = app.addMovieToList(list, 'Thor', '4:30pm');
const expected = [
{ name: 'Jurassic World 2’, showTime: ‘7:00pm’, ticketsRemaining: 47 },
{ name: ‘Thor', showTime: ‘4:30pm', ticketsRemaining: 100 }
];
expect(results).toBe(expected);
expect(results).toEqual(expected);
});
});