SlideShare a Scribd company logo
1 of 30
402/55 LIME ST > SYDNEY NSW 2000 > AUSTRALIA > WWW.OCTO.COM.AU
CEDRIC NICOLOSO - DEC. 2017
VUE TESTING
Going through the pyramid of tests
WHOAMI
Cedric Nicoloso
IT Consultant / Front-end dev
@OCTODownUnder
2
THE PYRAMID OF TESTS
 Unit tests are fast and cheap
 UI / E2E tests are slow and expensive
Martin Fowler https://martinfowler.com/bliki/TestPyramid.html
3
THE TESTS PYRAMID… REVISITED!
 Includes functions unit tests
 Includes snapshot tests
Inspired by Edd Yerburgh https://medium.freecodecamp.org/the-front-end-test-pyramid-rethink-your-testing-3b343c2bca51
4
>01 FUNCTIONS UNIT TESTS
6
KEY POINTS
Test JavaScript functions (ideally pure)
No need to mount my component
Framework-agnostic
7
“user-score.service.js”
MOCHA-WEBPACK
1. Ask webpack to create a bundle
> Our test files
> Functions we want to test
2. Call mocha on this bundle
8
 Extract these JS functions into separate “service” files
 Lighter components
 TDD-friendly
>02 COMPONENTS UNIT TESTS
10
11
WEB COMPONENTS (1/2)
WEB COMPONENTS (2/2)
12
App
Left menu Top toolbar
Sign-in buttonMenu item
Main content
Home page
Map Tutorial dialog Unlock dialog …
Question box … …
Depends on the active route
SHALLOW RENDERING
Render a component without its
children (by stubbing them)
13
Avoid asserting the behavior of child components
Faster to render
Included in vue-test-utils
Top toolbar
Sign-in button
FOCUS ON VUE-TEST-UTILS
Provides utility functions, makes things easier to test
> Mounting
> Traversing the DOM
> Triggering and catching events
> Etc…
Returns a wrapper around the mounted Component instance
> const wrapper = mount(MyComponent)
> const wrapper = shallow(MyComponent)
For example, we can access emitted events through this wrapper
> And make assertions on them
14
Mocha (The classic one)
Bring your own
> Assertions (chai, should…)
> Mocks (sinon, testdouble…)
> Coverage (Istanbul)
Real browsers with Karma
Jest (The new one)
All inclusive
> Uses popular solutions like
Jasmine and Istanbul under the
hood
New default test stack in vue-
cli webpack template
TWO MAIN CHOICES
>03 SNAPSHOT TESTS
17
USE SNAPSHOTS WITH JEST
Sometimes your UI changes too often
> You have to update your tests all the time…
“Just notice me when there is a change!”
> And I’ll tell you if this is expected or not
18
It will save your rendered component
> Creates and stores *.snap files in __snapshots__ folder
Works out-of-the-box with Jest
> expect(vm.$el.outerHTML).toMatchSnapshot()
WHEN IT FAILS
19
 Fails if your rendered component doesn’t match the previous snapshot
 Two options:
> Fix your code
> Tell Jest to update its snapshot
>04 Time to retire for Selenium
21
Open-source
No Selenium dependency!
Uses your favourite tools under the hood
> Mocha
> Chai
> Sinon
Automatic waiting
> More consistent results
> No need of random ‘sleeping times’ everywhere
Readable errors
22
CYPRESS - INTRODUCTION
CYPRESS.IO - API
Ability to stub server
requests with fixtures
Works well with promises
Includes jQuery
Change viewport
23
INSTALL IT AND OPEN IT
Install cypress as a dev dependency
> npm install cypress –save-dev (200 Mb...)
Cypress GUI
24
RUN IT
25
WHEN IT FAILS…
26
> WHAT’S TO REMEMBER?
YOUR TAKE-AWAYS
 Feasible to quickly unit test JavaScript functions
28
 Jest is becoming more and more popular
 Snapshot tests are a great new type of tests
 Cypress.io is a viable and sexy alternative to Selenium
ROTI TIME
29
1 2 3 4 5
30

More Related Content

What's hot

Using protractor to build automated ui tests
Using protractor to build automated ui testsUsing protractor to build automated ui tests
Using protractor to build automated ui tests🌱 Dale Spoonemore
 
Java Tools and Techniques for Solving Tricky Problem
Java Tools and Techniques for Solving Tricky ProblemJava Tools and Techniques for Solving Tricky Problem
Java Tools and Techniques for Solving Tricky ProblemWill Iverson
 
Backbone.js
Backbone.jsBackbone.js
Backbone.jsVO Tho
 
Painless JavaScript Testing with Jest
Painless JavaScript Testing with JestPainless JavaScript Testing with Jest
Painless JavaScript Testing with JestMichał Pierzchała
 
Unit Testing with Jest
Unit Testing with JestUnit Testing with Jest
Unit Testing with JestMaayan Glikser
 
Introduction to PhantomJS
Introduction to PhantomJSIntroduction to PhantomJS
Introduction to PhantomJSErol Selitektay
 
AngularJS - Overcoming performance issues. Limits.
AngularJS - Overcoming performance issues. Limits.AngularJS - Overcoming performance issues. Limits.
AngularJS - Overcoming performance issues. Limits.Dragos Mihai Rusu
 
One step in the future: CSS variables
One step in the future: CSS variablesOne step in the future: CSS variables
One step in the future: CSS variablesGiacomo Zinetti
 
So You Want To Write Your Own Benchmark
So You Want To Write Your Own BenchmarkSo You Want To Write Your Own Benchmark
So You Want To Write Your Own BenchmarkDror Bereznitsky
 
Testing MeteorJS using CasperJS
Testing MeteorJS using CasperJSTesting MeteorJS using CasperJS
Testing MeteorJS using CasperJSStephan Hochhaus
 
Javascript testing: tools of the trade
Javascript testing: tools of the tradeJavascript testing: tools of the trade
Javascript testing: tools of the tradeJuanma Orta
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaChristopher Bartling
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmineTimothy Oxley
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS偉格 高
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineGil Fink
 

What's hot (20)

Using protractor to build automated ui tests
Using protractor to build automated ui testsUsing protractor to build automated ui tests
Using protractor to build automated ui tests
 
Java Tools and Techniques for Solving Tricky Problem
Java Tools and Techniques for Solving Tricky ProblemJava Tools and Techniques for Solving Tricky Problem
Java Tools and Techniques for Solving Tricky Problem
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Painless JavaScript Testing with Jest
Painless JavaScript Testing with JestPainless JavaScript Testing with Jest
Painless JavaScript Testing with Jest
 
Unit Testing with Jest
Unit Testing with JestUnit Testing with Jest
Unit Testing with Jest
 
Cache is King
Cache is KingCache is King
Cache is King
 
Metasploit primary
Metasploit primaryMetasploit primary
Metasploit primary
 
Introduction to PhantomJS
Introduction to PhantomJSIntroduction to PhantomJS
Introduction to PhantomJS
 
AngularJS - Overcoming performance issues. Limits.
AngularJS - Overcoming performance issues. Limits.AngularJS - Overcoming performance issues. Limits.
AngularJS - Overcoming performance issues. Limits.
 
One step in the future: CSS variables
One step in the future: CSS variablesOne step in the future: CSS variables
One step in the future: CSS variables
 
So You Want To Write Your Own Benchmark
So You Want To Write Your Own BenchmarkSo You Want To Write Your Own Benchmark
So You Want To Write Your Own Benchmark
 
PHP-VCR Lightningtalk
PHP-VCR LightningtalkPHP-VCR Lightningtalk
PHP-VCR Lightningtalk
 
PHP-VCR behat case study
PHP-VCR behat case studyPHP-VCR behat case study
PHP-VCR behat case study
 
Testing MeteorJS using CasperJS
Testing MeteorJS using CasperJSTesting MeteorJS using CasperJS
Testing MeteorJS using CasperJS
 
Javascript testing: tools of the trade
Javascript testing: tools of the tradeJavascript testing: tools of the trade
Javascript testing: tools of the trade
 
JavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and KarmaJavaScript TDD with Jasmine and Karma
JavaScript TDD with Jasmine and Karma
 
Intro to testing Javascript with jasmine
Intro to testing Javascript with jasmineIntro to testing Javascript with jasmine
Intro to testing Javascript with jasmine
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
 
Quick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmineQuick tour to front end unit testing using jasmine
Quick tour to front end unit testing using jasmine
 
Up & running with jasmine
Up & running with jasmineUp & running with jasmine
Up & running with jasmine
 

Similar to Vue Testing - Vue Sydney Meetup - Dec 2017

Dragos Rusu - Angular JS - Overcoming Performance Issues - CodeCamp-10-may-2014
Dragos Rusu  - Angular JS - Overcoming Performance Issues - CodeCamp-10-may-2014Dragos Rusu  - Angular JS - Overcoming Performance Issues - CodeCamp-10-may-2014
Dragos Rusu - Angular JS - Overcoming Performance Issues - CodeCamp-10-may-2014Codecamp Romania
 
Implementing Quality on a Java Project
Implementing Quality on a Java ProjectImplementing Quality on a Java Project
Implementing Quality on a Java ProjectVincent Massol
 
Comment j'ai mis ma suite de tests au régime en 5 minutes par jour
Comment j'ai mis ma suite de tests au régime en 5 minutes par jourComment j'ai mis ma suite de tests au régime en 5 minutes par jour
Comment j'ai mis ma suite de tests au régime en 5 minutes par jourCARA_Lyon
 
Containerize your Blackbox tests
Containerize your Blackbox testsContainerize your Blackbox tests
Containerize your Blackbox testsKevin Beeman
 
Android Unit Test
Android Unit TestAndroid Unit Test
Android Unit TestPhuoc Bui
 
Continuos integration for iOS projects
Continuos integration for iOS projectsContinuos integration for iOS projects
Continuos integration for iOS projectsAleksandra Gavrilovska
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010Arun Gupta
 
Jazoon12 355 aleksandra_gavrilovska-1
Jazoon12 355 aleksandra_gavrilovska-1Jazoon12 355 aleksandra_gavrilovska-1
Jazoon12 355 aleksandra_gavrilovska-1Netcetera
 
Gitter marionette deck
Gitter marionette deckGitter marionette deck
Gitter marionette deckMike Bartlett
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxAna-Maria Mihalceanu
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slidesDavid Barreto
 
Docker–Grid (A On demand and Scalable dockerized selenium grid architecture)
Docker–Grid (A On demand and Scalable dockerized selenium grid architecture)Docker–Grid (A On demand and Scalable dockerized selenium grid architecture)
Docker–Grid (A On demand and Scalable dockerized selenium grid architecture)STePINForum
 
Node.js Community Benchmarking WG update
Node.js Community  Benchmarking WG updateNode.js Community  Benchmarking WG update
Node.js Community Benchmarking WG updateMichael Dawson
 
Dive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceDive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceOleksii Prohonnyi
 
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...Ondřej Machulda
 
UI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected JourneyUI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected JourneyOren Farhi
 
Implementing quality in Java projects
Implementing quality in Java projectsImplementing quality in Java projects
Implementing quality in Java projectsVincent Massol
 
Take control of your Jenkins jobs via job DSL.
Take control of your Jenkins jobs via job DSL.Take control of your Jenkins jobs via job DSL.
Take control of your Jenkins jobs via job DSL.Łukasz Proszek
 

Similar to Vue Testing - Vue Sydney Meetup - Dec 2017 (20)

Dragos Rusu - Angular JS - Overcoming Performance Issues - CodeCamp-10-may-2014
Dragos Rusu  - Angular JS - Overcoming Performance Issues - CodeCamp-10-may-2014Dragos Rusu  - Angular JS - Overcoming Performance Issues - CodeCamp-10-may-2014
Dragos Rusu - Angular JS - Overcoming Performance Issues - CodeCamp-10-may-2014
 
Implementing Quality on a Java Project
Implementing Quality on a Java ProjectImplementing Quality on a Java Project
Implementing Quality on a Java Project
 
Comment j'ai mis ma suite de tests au régime en 5 minutes par jour
Comment j'ai mis ma suite de tests au régime en 5 minutes par jourComment j'ai mis ma suite de tests au régime en 5 minutes par jour
Comment j'ai mis ma suite de tests au régime en 5 minutes par jour
 
Containerize your Blackbox tests
Containerize your Blackbox testsContainerize your Blackbox tests
Containerize your Blackbox tests
 
Agility Requires Safety
Agility Requires SafetyAgility Requires Safety
Agility Requires Safety
 
Android Unit Test
Android Unit TestAndroid Unit Test
Android Unit Test
 
Continuos integration for iOS projects
Continuos integration for iOS projectsContinuos integration for iOS projects
Continuos integration for iOS projects
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
 
Jazoon12 355 aleksandra_gavrilovska-1
Jazoon12 355 aleksandra_gavrilovska-1Jazoon12 355 aleksandra_gavrilovska-1
Jazoon12 355 aleksandra_gavrilovska-1
 
Gitter marionette deck
Gitter marionette deckGitter marionette deck
Gitter marionette deck
 
OpenCms Days 2015 Workflow using Docker and Jenkins
OpenCms Days 2015 Workflow using Docker and JenkinsOpenCms Days 2015 Workflow using Docker and Jenkins
OpenCms Days 2015 Workflow using Docker and Jenkins
 
A Glance At The Java Performance Toolbox
A Glance At The Java Performance ToolboxA Glance At The Java Performance Toolbox
A Glance At The Java Performance Toolbox
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slides
 
Docker–Grid (A On demand and Scalable dockerized selenium grid architecture)
Docker–Grid (A On demand and Scalable dockerized selenium grid architecture)Docker–Grid (A On demand and Scalable dockerized selenium grid architecture)
Docker–Grid (A On demand and Scalable dockerized selenium grid architecture)
 
Node.js Community Benchmarking WG update
Node.js Community  Benchmarking WG updateNode.js Community  Benchmarking WG update
Node.js Community Benchmarking WG update
 
Dive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceDive into Angular, part 5: Experience
Dive into Angular, part 5: Experience
 
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
 
UI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected JourneyUI Testing Best Practices - An Expected Journey
UI Testing Best Practices - An Expected Journey
 
Implementing quality in Java projects
Implementing quality in Java projectsImplementing quality in Java projects
Implementing quality in Java projects
 
Take control of your Jenkins jobs via job DSL.
Take control of your Jenkins jobs via job DSL.Take control of your Jenkins jobs via job DSL.
Take control of your Jenkins jobs via job DSL.
 

Recently uploaded

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

Vue Testing - Vue Sydney Meetup - Dec 2017

  • 1. 402/55 LIME ST > SYDNEY NSW 2000 > AUSTRALIA > WWW.OCTO.COM.AU CEDRIC NICOLOSO - DEC. 2017 VUE TESTING Going through the pyramid of tests
  • 2. WHOAMI Cedric Nicoloso IT Consultant / Front-end dev @OCTODownUnder 2
  • 3. THE PYRAMID OF TESTS  Unit tests are fast and cheap  UI / E2E tests are slow and expensive Martin Fowler https://martinfowler.com/bliki/TestPyramid.html 3
  • 4. THE TESTS PYRAMID… REVISITED!  Includes functions unit tests  Includes snapshot tests Inspired by Edd Yerburgh https://medium.freecodecamp.org/the-front-end-test-pyramid-rethink-your-testing-3b343c2bca51 4
  • 6. 6
  • 7. KEY POINTS Test JavaScript functions (ideally pure) No need to mount my component Framework-agnostic 7 “user-score.service.js”
  • 8. MOCHA-WEBPACK 1. Ask webpack to create a bundle > Our test files > Functions we want to test 2. Call mocha on this bundle 8  Extract these JS functions into separate “service” files  Lighter components  TDD-friendly
  • 10. 10
  • 12. WEB COMPONENTS (2/2) 12 App Left menu Top toolbar Sign-in buttonMenu item Main content Home page Map Tutorial dialog Unlock dialog … Question box … … Depends on the active route
  • 13. SHALLOW RENDERING Render a component without its children (by stubbing them) 13 Avoid asserting the behavior of child components Faster to render Included in vue-test-utils Top toolbar Sign-in button
  • 14. FOCUS ON VUE-TEST-UTILS Provides utility functions, makes things easier to test > Mounting > Traversing the DOM > Triggering and catching events > Etc… Returns a wrapper around the mounted Component instance > const wrapper = mount(MyComponent) > const wrapper = shallow(MyComponent) For example, we can access emitted events through this wrapper > And make assertions on them 14
  • 15. Mocha (The classic one) Bring your own > Assertions (chai, should…) > Mocks (sinon, testdouble…) > Coverage (Istanbul) Real browsers with Karma Jest (The new one) All inclusive > Uses popular solutions like Jasmine and Istanbul under the hood New default test stack in vue- cli webpack template TWO MAIN CHOICES
  • 17. 17
  • 18. USE SNAPSHOTS WITH JEST Sometimes your UI changes too often > You have to update your tests all the time… “Just notice me when there is a change!” > And I’ll tell you if this is expected or not 18 It will save your rendered component > Creates and stores *.snap files in __snapshots__ folder Works out-of-the-box with Jest > expect(vm.$el.outerHTML).toMatchSnapshot()
  • 19. WHEN IT FAILS 19  Fails if your rendered component doesn’t match the previous snapshot  Two options: > Fix your code > Tell Jest to update its snapshot
  • 20. >04 Time to retire for Selenium
  • 21. 21
  • 22. Open-source No Selenium dependency! Uses your favourite tools under the hood > Mocha > Chai > Sinon Automatic waiting > More consistent results > No need of random ‘sleeping times’ everywhere Readable errors 22 CYPRESS - INTRODUCTION
  • 23. CYPRESS.IO - API Ability to stub server requests with fixtures Works well with promises Includes jQuery Change viewport 23
  • 24. INSTALL IT AND OPEN IT Install cypress as a dev dependency > npm install cypress –save-dev (200 Mb...) Cypress GUI 24
  • 27. > WHAT’S TO REMEMBER?
  • 28. YOUR TAKE-AWAYS  Feasible to quickly unit test JavaScript functions 28  Jest is becoming more and more popular  Snapshot tests are a great new type of tests  Cypress.io is a viable and sexy alternative to Selenium
  • 30. 30

Editor's Notes

  1. Alright, let’s kick off this session1 So for the next 20-ish minutes, I’ll be talking about Vue (of course) and more specifically about tests.
  2. Before starting, my name is Cedric. I work at OCTO as an IT conultant, and the subject that I like the most is… frontend development.
  3. Alright, everybody has already seen that, at least once? Martin Fowler, 5 years ago. Cheap in the sense of “They are easy to write” and “Easy to maintain”. Unit tests are good for TDD.
  4. No more service tests? Depends on what you mean by service, but I guess it could be covered by the first slices we have here. A full component, with its child components could be seen as a service, or at a least a part of your system…
  5. Not really mainstream, I know. I started to be interested in that when I was working with a big codebase in Angular 2, and running the tests was crazy slow. Because there was a lot of dependencies to load. Not motivated to run them. Not motivated to create new ones. So I kinda wanted to find a solution…
  6. First of all, be careful, those tests are slow, and easy to break. But still, sometimes it can be very useful to test an entire workflow. To simulate a user interaction with our webapp. For quite a while there has been one major player in here  —  Selenium. Most of the other solutions out there are basically building their APIs on top of selenium, so they all suffer from the same problems that selenium has.
  7. Sometimes I need a way of testing a simple JavaScript function. I don’t need to mount a component or anything… Let’s take an example… Here I have a player, each time he answers correctly to one question, there is a new line in the DB, and I want to calculate his total score. And I obviously want to test that.
  8. And usually what I use for that is mocha-webpack. It will force you to extract some of your logic out of your component. It will force you to write these functions in a more testable way. I’m sure you have in your projects some pure JavaScript functions, that don’t depend on your frontend framework, and that you could easily test like that. So I encourage you to have a look.
  9. Alright, next kind of tests in our new pyramid…
  10. So, everyone knows what a “component” is…
  11. We can also represent that as a tree of components. As you can see, most of our components have child components. And it’s interesting to keep that in mind when it comes to testing. Most of the time, we want to test our components in isolation. At least when we talk about unit tests. Take the example of the ”Top toolbar”, if I want to test the value of my title for example, I don’t really want to render the “Sign-in button” child component. Actually, I want to stub it.
  12. That brings me to explain what “shallow rendering is”. Faster to render, important if you re-render your entire component before each of your tests. We need this “shallow rendering”, and it’s included in vue-test-utils, let’s talk about it. Vue-test-utils: https://vue-test-utils.vuejs.org/en/guides/common-tips.html
  13. So vue-test-utils is the reference test library for Vue.js. Vue-test-utils still in beta. Replacement for “avoriaz” (Same guy) So, we start from Vue.js, and then we have a test utility library, which will make our life easier as a developer, and now we want…
  14. Pull-request which got merged 3 weeks ago. On Jest, no real solution for running your tests in a real browser… Facebook says: “It’s too slow, too flaky, we ran away from it.” Recently, some people tried to use Puppeteer (a Node.js library for controlling headless Chrome) https://www.valentinog.com/blog/ui-testing-jest-puppetteer/ PR: “Replace Karma + Mocha with Jest” (opened July 26th  merged November 12th) https://github.com/vuejs-templates/webpack/pull/824 There is more choices with “avoriaz”. (Tape, Ava…) Difference between jsdom and PhantomJS: https://github.com/tmpvar/jsdom/wiki/jsdom-vs.-PhantomJS
  15. Introduced by Jest and React.
  16. <h2> instead of <h3> All good? Quite high in the pyramid of tests but actually it’s not expensive. It’s easy to write, fast to run. It’s just high in the pyramid because it covers more than your unit tests, it covers your entire template.
  17. And last slice of the pyramid! You remember the pyramid from the beginning?
  18. First of all, be careful, those tests are slow, and easy to break. But still, sometimes it can be very useful to test an entire workflow. To simulate a user interaction with our webapp. For quite a while there has been one major player in here  —  Selenium. Most of the other solutions out there are basically building their APIs on top of selenium, so they all suffer from the same problems that selenium has.
  19. Open-source, except for the team dashboard. I’ve also seen yesterday that it is part of the last edition of the Thoughtworks tech radar. https://assets.thoughtworks.com/assets/technology-radar-vol-17-en.pdf Selenium WebDriver runs remotely outside the browser, Cypress runs inside the browser. https://hackernoon.com/cypress-io-docker-the-ultimate-e2e-stack-a20ee25654b1 https://blog.red-badger.com/blog/2017/6/16/cypress-a-genuine-alternative-to-selenium-at-last https://www.joecolantonio.com/2017/11/16/cypress-io-vs-selenium-test-automation/ Selenium versus Cypress.io https://gist.github.com/jennifer-shehane/eaa017496b9b5cfc98e8f4ef31a437fc https://github.com/cypress-io/cypress Written in CoffeeScript Supported browsers: https://docs.cypress.io/guides/core-concepts/launching-browsers.html#Browsers
  20. Promises. Here I first get a DOM element, I make an assertion “It should be visible”, and then once it is and only once it is, I continue… jQuery. In case you need some fancy selectors or you want to access the content of a DOM element to make more advances assertions.
  21. Show the video! (if time)
  22. Start testing with Jest and vue-test-utils https://blog.codeship.com/get-started-with-vue-test-utils-and-jest A future book on how to efficiently test Vue.js applications by vue-test-utils author https://www.manning.com/books/testing-vuejs-applications “Why Cypress?” by Cypress team https://docs.cypress.io/guides/overview/why-cypress.html A Cypress.io set of slides http://slides.com/bahmutov/effective-e2e-testing-with-cypress