SlideShare a Scribd company logo
Testando meus componentes com Vue Test Utils
Daniel Santos
Full Stack Developer
Just Digital
Daniel Santos - Apache
daniel@justdigital.com.br
@apachetec
instagram.com/apachetec
slideshare.com/apachetec
github.com/daniiell3
Por que testar?
"You wouldn’t write the sign-up form, and send it off to your boss
without checking that it works (at least I hope you wouldn’t). No,
you’d manually test it. So, the question isn’t why test. The question
is why use automated testing?" (EDD YERBURGH, 2017, Why
test Vue applications?)
Por que testes automatizados?
"There are two big problems when you test your code
manually. The amount time it takes and human error." (EDD
YERBURGH, 2017, Why test Vue applications?)
Tempo
Tempo
"Flávio, você abriria um posto de gasolina? Posto de gasolina
tem em média 3% de margem, meu tempo vale mais do
que 3% de margem" (FLÁVIO AUGUSTO, 2018,
Ferramentas para avaliar seu negócio)
O que é teste unitário?
"Unit tests are a way to automatically check that our code does
what it’s meant to do. We run the code in a controlled environment
and assert that functions produce the expected output." (EDD
YERBURGH, 2017, How to unit test Vue components for
beginners)
@vue/test-utils
Jest
"We observed that when engineers are provided with ready-
to-use tools, they end up writing more tests, which in turn
results in more stable and healthy code bases."
Nativo
const Constructor = Vue.extend(Foo)
const vm = new Constructor().$mount()
Mount/Shallow
@vue/test-utils
const wrapper = mount(Foo)
avoriaz
const wrapper = shallow(Foo)
const div = wrapper.first('div')
Find
@vue/test-utils
const wrapper = shallow(Foo)
const div = wrapper.find('div')
avoriaz
const wrapper = shallow(Foo)
const div = wrapper.find('div')
FindAll
@vue/test-utils
const wrapper = shallow(Foo)
const div = wrapper.findAll('div')
Find by ref
@vue/test-utils
const wrapper = shallow(Foo)
const div = wrapper.find({ ref: ‘title' })
avoriaz
const wrapper = shallow(Foo)
const isActive = wrapper.first('div').hasClass('active')
Classes
@vue/test-utils
const wrapper = shallow(Foo)
const classes = wrapper.find('div').classes()
avoriaz
const wrapper = shallow(Foo)
const src = wrapper.first('img').getAttribute('src')
Attributes
@vue/test-utils
const wrapper = shallow(Foo)
const src = wrapper.find('img').attributes().src
● WrapperArray
● createLocalVue
● mocks
Algumas das novidades na API do @vue/test-utils
OdontoPrev
Conclusão:
● Use mount() com moderação
● Pure Components
● CSS Namespace
● Refatoração
● CodeceptJS
● Valorize seu TEMPO
Obrigado!!!

More Related Content

What's hot

Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
Peter Drinnan
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
Jim Lynch
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
Knoldus Inc.
 
Working Software Over Comprehensive Documentation
Working Software Over Comprehensive DocumentationWorking Software Over Comprehensive Documentation
Working Software Over Comprehensive Documentation
Andrii Dzynia
 
Testing of React JS app
Testing of React JS appTesting of React JS app
Testing of React JS app
Aleks Zinevych
 
Nightwatch JS for End to End Tests
Nightwatch JS for End to End TestsNightwatch JS for End to End Tests
Nightwatch JS for End to End Tests
Sriram Angajala
 
Client side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karmaClient side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karma
Adam Klein
 
Automated Web Testing using JavaScript
Automated Web Testing using JavaScriptAutomated Web Testing using JavaScript
Automated Web Testing using JavaScript
Simon Guest
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
Luís Bastião Silva
 
Unit testing on mobile apps
Unit testing on mobile appsUnit testing on mobile apps
Unit testing on mobile apps
Buşra Deniz, CSM
 
Protractor: Tips & Tricks
Protractor: Tips & TricksProtractor: Tips & Tricks
Protractor: Tips & Tricks
Sergey Bolshchikov
 
Testing Big in JavaScript
Testing Big in JavaScriptTesting Big in JavaScript
Testing Big in JavaScript
Robert DeLuca
 
UI Testing Automation
UI Testing AutomationUI Testing Automation
UI Testing Automation
AgileEngine
 
JavaScript + Jenkins = Winning!
JavaScript + Jenkins = Winning!JavaScript + Jenkins = Winning!
JavaScript + Jenkins = Winning!
Eric Wendelin
 
Secure your Web Application With The New Python Audit Hooks
Secure your Web Application With The New Python Audit HooksSecure your Web Application With The New Python Audit Hooks
Secure your Web Application With The New Python Audit Hooks
Nicolas Vivet
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit Test
Chiew Carol
 
Insights on Protractor testing
Insights on Protractor testingInsights on Protractor testing
Insights on Protractor testing
Dejan Toteff
 
Test Drive Development in Ruby On Rails
Test Drive Development in Ruby On RailsTest Drive Development in Ruby On Rails
Test Drive Development in Ruby On Rails
Nyros Technologies
 
Testing frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTesting frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabs
Tudor Barbu
 
Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)
Alin Pandichi
 

What's hot (20)

Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 
Automated Testing in Angular Slides
Automated Testing in Angular SlidesAutomated Testing in Angular Slides
Automated Testing in Angular Slides
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
Working Software Over Comprehensive Documentation
Working Software Over Comprehensive DocumentationWorking Software Over Comprehensive Documentation
Working Software Over Comprehensive Documentation
 
Testing of React JS app
Testing of React JS appTesting of React JS app
Testing of React JS app
 
Nightwatch JS for End to End Tests
Nightwatch JS for End to End TestsNightwatch JS for End to End Tests
Nightwatch JS for End to End Tests
 
Client side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karmaClient side unit tests - using jasmine & karma
Client side unit tests - using jasmine & karma
 
Automated Web Testing using JavaScript
Automated Web Testing using JavaScriptAutomated Web Testing using JavaScript
Automated Web Testing using JavaScript
 
Browser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.jsBrowser Automated Testing Frameworks - Nightwatch.js
Browser Automated Testing Frameworks - Nightwatch.js
 
Unit testing on mobile apps
Unit testing on mobile appsUnit testing on mobile apps
Unit testing on mobile apps
 
Protractor: Tips & Tricks
Protractor: Tips & TricksProtractor: Tips & Tricks
Protractor: Tips & Tricks
 
Testing Big in JavaScript
Testing Big in JavaScriptTesting Big in JavaScript
Testing Big in JavaScript
 
UI Testing Automation
UI Testing AutomationUI Testing Automation
UI Testing Automation
 
JavaScript + Jenkins = Winning!
JavaScript + Jenkins = Winning!JavaScript + Jenkins = Winning!
JavaScript + Jenkins = Winning!
 
Secure your Web Application With The New Python Audit Hooks
Secure your Web Application With The New Python Audit HooksSecure your Web Application With The New Python Audit Hooks
Secure your Web Application With The New Python Audit Hooks
 
AngularJS Unit Test
AngularJS Unit TestAngularJS Unit Test
AngularJS Unit Test
 
Insights on Protractor testing
Insights on Protractor testingInsights on Protractor testing
Insights on Protractor testing
 
Test Drive Development in Ruby On Rails
Test Drive Development in Ruby On RailsTest Drive Development in Ruby On Rails
Test Drive Development in Ruby On Rails
 
Testing frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTesting frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabs
 
Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)Unit Testing your React / Redux app (@BucharestJS)
Unit Testing your React / Redux app (@BucharestJS)
 

Similar to Testando meus componentes com vue test utils

Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
davejohnson
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
Eric Selje
 
Testing Options in Java
Testing Options in JavaTesting Options in Java
Testing Options in Java
Michael Fons
 
UI Testing
UI TestingUI Testing
UI Testing
Josh Black
 
Testacular
TestacularTestacular
Testacular
James Ford
 
Testing with VS2010 - A Bugs Life
Testing with VS2010 - A Bugs LifeTesting with VS2010 - A Bugs Life
Testing with VS2010 - A Bugs Life
Peter Gfader
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
Scott Leberknight
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
Jon Kruger
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
Mats Bryntse
 
We continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShell
PVS-Studio
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
SpringPeople
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
Attila Bertók
 
1 aleksandr gritsevski - attd example using
1   aleksandr gritsevski - attd example using1   aleksandr gritsevski - attd example using
1 aleksandr gritsevski - attd example using
Ievgenii Katsan
 
Unit Testing in iOS
Unit Testing in iOSUnit Testing in iOS
Unit Testing in iOS
Long Weekend LLC
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
Gianluca Padovani
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Steven Pignataro
 
JavaOne 2017 CON2902 - Java Code Inspection and Testing Power Tools
JavaOne 2017 CON2902 - Java Code Inspection and Testing Power ToolsJavaOne 2017 CON2902 - Java Code Inspection and Testing Power Tools
JavaOne 2017 CON2902 - Java Code Inspection and Testing Power Tools
Jorge Hidalgo
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
Facundo Farias
 
Writing useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you buildWriting useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you build
Andrei Sebastian Cîmpean
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Comunidade NetPonto
 

Similar to Testando meus componentes com vue test utils (20)

Pragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScriptPragmatic Parallels: Java and JavaScript
Pragmatic Parallels: Java and JavaScript
 
SELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdfSELJE_Database_Unit_Testing.pdf
SELJE_Database_Unit_Testing.pdf
 
Testing Options in Java
Testing Options in JavaTesting Options in Java
Testing Options in Java
 
UI Testing
UI TestingUI Testing
UI Testing
 
Testacular
TestacularTestacular
Testacular
 
Testing with VS2010 - A Bugs Life
Testing with VS2010 - A Bugs LifeTesting with VS2010 - A Bugs Life
Testing with VS2010 - A Bugs Life
 
Unit Testing
Unit TestingUnit Testing
Unit Testing
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Java script unit testing
Java script unit testingJava script unit testing
Java script unit testing
 
We continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShellWe continue checking Microsoft projects: analysis of PowerShell
We continue checking Microsoft projects: analysis of PowerShell
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
TDD Best Practices
TDD Best PracticesTDD Best Practices
TDD Best Practices
 
1 aleksandr gritsevski - attd example using
1   aleksandr gritsevski - attd example using1   aleksandr gritsevski - attd example using
1 aleksandr gritsevski - attd example using
 
Unit Testing in iOS
Unit Testing in iOSUnit Testing in iOS
Unit Testing in iOS
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
 
JavaOne 2017 CON2902 - Java Code Inspection and Testing Power Tools
JavaOne 2017 CON2902 - Java Code Inspection and Testing Power ToolsJavaOne 2017 CON2902 - Java Code Inspection and Testing Power Tools
JavaOne 2017 CON2902 - Java Code Inspection and Testing Power Tools
 
TDD Workshop UTN 2012
TDD Workshop UTN 2012TDD Workshop UTN 2012
TDD Workshop UTN 2012
 
Writing useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you buildWriting useful automated tests for the single page applications you build
Writing useful automated tests for the single page applications you build
 
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...Testes? Mas isso não aumenta o tempo de projecto? Não quero...
Testes? Mas isso não aumenta o tempo de projecto? Não quero...
 

Recently uploaded

Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Jeffrey Haguewood
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
Shinana2
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 

Recently uploaded (20)

Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
dbms calicut university B. sc Cs 4th sem.pdf
dbms  calicut university B. sc Cs 4th sem.pdfdbms  calicut university B. sc Cs 4th sem.pdf
dbms calicut university B. sc Cs 4th sem.pdf
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 

Testando meus componentes com vue test utils

  • 1. Testando meus componentes com Vue Test Utils Daniel Santos Full Stack Developer Just Digital
  • 2. Daniel Santos - Apache daniel@justdigital.com.br @apachetec instagram.com/apachetec slideshare.com/apachetec github.com/daniiell3
  • 3.
  • 4. Por que testar? "You wouldn’t write the sign-up form, and send it off to your boss without checking that it works (at least I hope you wouldn’t). No, you’d manually test it. So, the question isn’t why test. The question is why use automated testing?" (EDD YERBURGH, 2017, Why test Vue applications?)
  • 5. Por que testes automatizados? "There are two big problems when you test your code manually. The amount time it takes and human error." (EDD YERBURGH, 2017, Why test Vue applications?)
  • 7. Tempo "Flávio, você abriria um posto de gasolina? Posto de gasolina tem em média 3% de margem, meu tempo vale mais do que 3% de margem" (FLÁVIO AUGUSTO, 2018, Ferramentas para avaliar seu negócio)
  • 8.
  • 9. O que é teste unitário? "Unit tests are a way to automatically check that our code does what it’s meant to do. We run the code in a controlled environment and assert that functions produce the expected output." (EDD YERBURGH, 2017, How to unit test Vue components for beginners)
  • 11. Jest "We observed that when engineers are provided with ready- to-use tools, they end up writing more tests, which in turn results in more stable and healthy code bases."
  • 12. Nativo const Constructor = Vue.extend(Foo) const vm = new Constructor().$mount() Mount/Shallow @vue/test-utils const wrapper = mount(Foo)
  • 13.
  • 14.
  • 15. avoriaz const wrapper = shallow(Foo) const div = wrapper.first('div') Find @vue/test-utils const wrapper = shallow(Foo) const div = wrapper.find('div')
  • 16. avoriaz const wrapper = shallow(Foo) const div = wrapper.find('div') FindAll @vue/test-utils const wrapper = shallow(Foo) const div = wrapper.findAll('div')
  • 17. Find by ref @vue/test-utils const wrapper = shallow(Foo) const div = wrapper.find({ ref: ‘title' })
  • 18. avoriaz const wrapper = shallow(Foo) const isActive = wrapper.first('div').hasClass('active') Classes @vue/test-utils const wrapper = shallow(Foo) const classes = wrapper.find('div').classes()
  • 19. avoriaz const wrapper = shallow(Foo) const src = wrapper.first('img').getAttribute('src') Attributes @vue/test-utils const wrapper = shallow(Foo) const src = wrapper.find('img').attributes().src
  • 20. ● WrapperArray ● createLocalVue ● mocks Algumas das novidades na API do @vue/test-utils
  • 22.
  • 23. Conclusão: ● Use mount() com moderação ● Pure Components ● CSS Namespace ● Refatoração ● CodeceptJS ● Valorize seu TEMPO

Editor's Notes

  1. Agradecer ao Igor e Juscilan
  2. Estamos Contratando De estagiário a Sênior
  3. Você não implementaria um formulário de login, e enviaria para o seu chefe, sem checar se ele realmente funciona (pelo menos espero que não). Não, você faria o teste manualmente. Então, a questão não é por que testar. A questão é por que usar testes automatizados? Post: Por que testar aplicações Vue
  4. Existem dois grandes problemas quando você testa seu código manualmente. A quantidade de tempo gasto e o erro humano. Post: Por que testar aplicações Vue
  5. Eduardo Matos é Full Stack Developer na GetNinjas Integrante do "Dev Na Estrada"
  6. Nerdcast Empreendedor 37 - Ferramentas para avaliar seu negócio Flávio Augusto: Fundador da Wise Up e Presidente do Orlando City Contexto da conversa: "Eu não entro em negócio que não tenha, Escala e Margem." Quanto vale seu tempo?
  7. Teste unitário é a maneira de verificar automaticamente se o nosso código faz o que pretende fazer. Executamos o código em um ambiente controlado e afirmamos que as funções produzem o resultado esperado. Post: Como criar testes unitários em componentes Vue, para iniciantes
  8. Vue Test Utils é uma biblioteca baseada no Avoriaz, com o objetivo de facilitar a criação de testes unitários em componentes Vue O Avoriaz é baseado na biblioteca enzyme https://github.com/airbnb/enzyme 7 Masters: Testes unitários em apps Vue.js por Caio Incau https://setemasters.imasters.com.br/conversas/testes-unitarios-em-apps-vue-js-por-caio-incau/ Enzyme é uma biblioteca criada pela equipe do Airbnb, para facilitar a criação de testes unitários em componentes do react A API da Enzyme deve ser intuitiva e flexível, imitando a API do jQuery para manipulação e percurso de DOM. O Vue Test Utils abstrai os elementos internos do Vue. Então, tudo o que você precisa fazer é aprender a API Vue Test Utils. A Documentação do Vue Test Utils em português às vezes é um pouco desatualizada Na documentacao do vue https://vuejs.org/v2/guide/unit-testing.html sobre testes unitários, mostra-se alguns exemplos de como testar componentes, mas é muito custoso e trabalhoso implementar testes para o vue da forma padrão
  9. "Observamos que quando os engenheiros recebem ferramentas prontas para usar, acabam escrevendo mais testes, o que resulta em bases de código mais estáveis e saudáveis." Jest é uma ferramenta (test runner e framework) criada pelo time do facebook para auxiliar na escrita de testes automatizados (react) A partir da versão 3 do vue-cli, foi adicionado a opção de teste unitário com Jest
  10. Página da documentação do Avoriaz Existe um link para migração do Avoriaz para o Vue Test Utils
  11. vue-test-utils está em beta, e será lançado em breve. Quando o vue-test-utils estiver pronto, o avoriaz será descontinuado. avoriaz e vue-test-utils têm APIs semelhantes. Você pode usar este guia para migrar de avoriaz para vue-test-utils.
  12. Avoriaz: first |> querySelector O funcionamento se assemelha ao do querySelector, mas a implementação é feita de outra maneira Quase que por expressão regular https://github.com/eddyerburgh/avoriaz/blob/master/src/lib/find-matching-vnodes.js @vue/test-utils: find = querySelector https://github.com/vuejs/vue-test-utils/blob/dev/src/lib/find.js https://github.com/vuejs/vue-test-utils/blob/dev/src/lib/find-dom-nodes.js Melhorou muito a API de find no @vue/test-utils, foi acrescentado recursos novos para a busca de elementos, muito devido a alteração para querySelector
  13. Avoriaz: find |> querySelectorAll O funcionamento se assemelha ao do querySelectorAll, mas a implementação é feita de outra maneira Quase que por expressão regular https://github.com/eddyerburgh/avoriaz/blob/master/src/lib/find-matching-vnodes.js @vue/test-utils: findAll = querySelectorAll https://github.com/vuejs/vue-test-utils/blob/dev/src/lib/find.js https://github.com/vuejs/vue-test-utils/blob/dev/src/lib/find-dom-nodes.js Melhorou muito a API de find no @vue/test-utils, foi acrescentado recursos novos para a busca de elementos, muito devido a alteração para querySelector
  14. Foi acrescentado no @vue/test-utils, find por ref https://vue-test-utils.vuejs.org/en/api/selectors.html https://github.com/vuejs/vue-test-utils/blob/dev/src/lib/get-selector-type.js
  15. Avoriaz: O método hasClass, retorna um booleano, caso exista a classe @vue/test-utils: classes() retorna um array com todas as classes do elemento Com isso podemos utilizar: toContain(className) - Expect do Jest to.include(className) - Expect do Chai
  16. Avoriaz: Utiliza a API do DOM, e já retorna o valor do atributo @vue/test-utils: attributes() retorna um objeto com todos os atributos do elemento: (id, name, etc...)
  17. WrapperArray: É uma API justamente para trabalhar com um array de elementos createLocalVue: createLocalVue é uma função, que retorna uma instância local do Vue, onde você pode instalar plugins e etc, sem modificar em nada a instância original… Ex: No avoriaz para você fazer um teste com o Vuex ou vue-events, etc..., você precisava importar o Vue "import Vue from 'vue'" mocks: Mocks é uma forma de mockar algumas funcionalidades (plugin) sem precisar usar o createLocalVue por exemplo. Muito útil para vue-router, na documentação é sugerido usar mocks ao invés de createLocalVue para vue-router
  18. Executar o storybook com os componentes do projeto
  19. Livro do Edd "Testando aplicações Vue.js" O Post citado algumas vezes aqui na apresentação Why test Vue applications? (Por que testar aplicações Vue) É um resumo do primeiro capítulo do livro Mês passado (15 de fevereiro), aconteceu o vue.js amsterdam Com uma talk do Edd "Unit testing Vue components: Why test, what to test, and how to test Vue components" "Teste unitários para Componentes Vue: Por que testar, o que testar, e como testar componente Vue"
  20. Pure Components: Utilize o Storybook - https://storybook.js.org/basics/guide-vue/ CSS Namespace: É uma técnica para nomenclatura de classe, que utiliza prefixos para separar e definir o objetivo da classe. Ex: c-plan__title qa-plan__title js-plan__title https://csswizardry.com/2015/03/more-transparent-ui-code-with-namespaces/