SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Downloaden Sie, um offline zu lesen
GrandParadePoland
www.grandparade.co.uk
Component level testing of react app,
using enzyme
KraQA – 23.01.2018
Wojciech Czyżycki, Senior QA Engineer
Tomasz Suwaj, QA Engineer
Grand Parade, Central Services FrontEnd Team
Agenda
●Company & Project
○ About GP & WH
●Test approach
○ Agile@Scale transformation
○ Detecting vs Preventing bugs, testing earlier in lifecycle
●Testing in React.JS project
○ Main ideas & tools
○ Enzyme
■ introduction
■ DOMtesting - render, shallow, mount
■ Selectors, find, user actions simulation
○ DDT& Snapshots,
○ Reporting, timing, statistics
●Summary
○ Pros & cons of this solution
GrandParadePoland
www.grandparade.co.uk
Company & Project
GrandParadePoland
www.grandparade.co.uk
GrandParade
● Founded in 2007
● UK: London, PL: Kraków
● Products: apps,websites and commerce
platforms forthe sports,gaming and media
companies
● Acquisitionby WH in 2016
● Number of employees:~ 300
About company - GP
GrandParadePoland
www.grandparade.co.uk
About company - WH
GrandParadePoland
www.grandparade.co.uk
WilliamHill
● Founded in 1934
● Leading betting company
○ Retail
○ Online
■ Sports
■ Gaming
● UK, Gibraltar, Poland, Bulgaria, Italy,
Spain, USA, Australia and the
Philippines
● Number of employees:~16k
About project
• Registration application
• About 20 WH sites on desktop
• Banners, landing pages,promotions
• Bonus actions
• Analytics
• Challenges
• Technologicalconsistency
• Customization by CMS
• Multi-step
• Field order
• Componentversions
• Tests inCucumber/Selenium/Java
GrandParadePoland
www.grandparade.co.uk
Test approach
/GrandParadePoland
www.grandparade.co.uk
Agile@Scale transformation
What are we doing
• Scrum as default managementframework
• Reducing silos and building cross functionalteams
• Productcentred teams
• Putting trust (and responsibility) into teams
• High level of test automation – coverage 80-90% (code and functional)
• CI/CD processimprovements
GrandParadePoland
www.grandparade.co.uk
Test approach - Detecting bugs
Traditionalapproach
• QA silos – weak collaboration
• Late testing – usually after deployon test
environment
• Often lack of time to create automated tests
Results
• Low test code quality (lack of patterns)
• Slow and flaky E2E tests
• Low trust to automated tests results
• More and more manual work
GrandParadePoland
www.grandparade.co.uk
GrandParadePoland
www.grandparade.co.uk
Preventing bugs
Currentapproach
• Environment equippedwith tools for early testing
• QAs work close with developers,shared quality responsibility
• QA tests in dev project,obligatory codereview
• Automated test pipeline on push and merge
Results
• Early bug/inconsistencyidentification
• Better test code quality
• Very fast and stable componenttests
• High functional requirements coverage by automation
• Huge reductionof E2E test
GrandParadePoland
www.grandparade.co.uk
High cost
Low speed
Low cost
High speed
Exploratory
testing
Tools
● JavaScript ES6 + Babel
● Npm, yarn – package managers
● React.js – front-end framework
● Enzyme – testing tool for React.js
● JSDOM – headless browser
● Jest – test runner, assertion library, spy tool, optimized for React.js
● Mocha/Chai/Sinon – tools replaced by Jest
● Gitlab – code management tool, CI pipelines
● Allure – test report generator
GrandParadePoland
www.grandparade.co.uk
Project structure
● Tests in component directory
● Unit, component, integration tests
in the same directory
● Test mocks, helpers, user data
generators, DDT data in separate
common directory
● E2E tests in separate project
GrandParadePoland
www.grandparade.co.uk
Testing in React.JS project
GrandParadePoland
www.grandparade.co.uk
How React works
• Components – Componentis an object that encapsulates part of the app. Reusable and easy to test.
• Reactivity – Elements are rendered after every change
• Virtual DOM(DocumentObject Model) – Abstractequivalent of DOM, used to detect (by comparision) which
elements have changed and need to be re-rendered
• JSX – Allows to pass JS objects into HTML, e.g.
<div>
<ObjectJS />
</ div>
GrandParadePoland
www.grandparade.co.uk
Enzyme – what it is?
Enzyme is a JavaScript Testing utility forReact that makes it easier to render, assert and manipulate your
React Components' output.
Enzyme – Airbnb projectwith more than 200 contributors
Decentdocumentationbut very general, with very basic examples
http://airbnb.io/enzyme/
GrandParadePoland
www.grandparade.co.uk
Enzyme – DOM testing
Shallow
• Don't render children
• Isolated - test cannot affecteach other
• Faster than Mount
Render
• Renders Static HTML structure
• With children
Mount
• Renders full DOM
• Includes the logic of components
• Testcan affecteach other
GrandParadePoland
www.grandparade.co.uk
.find()
<input type="text" id="reg-firstName" class="sb-input sb-input--error"
placeholder="" name="firstName" value="">
Supported CSS Selectors
ID element = wrapper.find('#reg-firstName');
Class Name element = wrapper.find('.sb-input');
Atribute element = wrapper.find('[name="firstName"]');
Elementtype element = wrapper.find('input[name="firstName"]');
Contextual element = wrapper.find('input.sb-input');
element = wrapper.find(('#reg-firstName > .sb-input-error');
GrandParadePoland
www.grandparade.co.uk
.find()
Not Supported Selectors
Pseudo Class element = wrapper.find('input:not([disabled])');
Enzyme received a pseudo-class CSS selector ('input:not([disabled])') that it does not currently support
Xpath element = wrapper.find('//*[@id="reg-firstName"]');
Supported getters
elements.first()
elements.last()
elements.at(n) – n-th element
Usage example:
element2 = wrapper.find('.sb-input').at(1)
GrandParadePoland
www.grandparade.co.uk
.simulate()
.simulate('focus')
.simulate('blur')
.simulate('click')
.simulate('change', { target: { value: 'New value' }})
When to use change?
• change dropdownvalue
• check/uncheckcheckbox
When to use click?
• click on button
• click on clickable span
GrandParadePoland
www.grandparade.co.uk
Jest assertions examples
.toBe()
expect(someBoolean).toBe(true);
.toEqual()
expect('chicken').toEqual('chicken');
expect(number).toEqual(5);
.toContain()
expect('fried chicken').toContain('chicken');
.toBeGreaterThan()
expect(100).toBeGreaterThan(99)
GrandParadePoland
www.grandparade.co.uk
Test examples
describe('Username field tests', () => {
beforeEach(() => {
wrapper = mount(
<Component {...props} />
);
});
it('Not a test, just console log',() => {
input = wrapper.find('#reg-firstName');
console.log(input.debug());
});
});
GrandParadePoland
www.grandparade.co.uk
Props Example
const props = {
name: 'username',
hintText:'USERNAME_HINT',
placeholder:'USERNAME_PLACEHOLDER',
...
}
GrandParadePoland
www.grandparade.co.uk
.debug() vs HTML in browser
<input id="reg-username" type="text" className="sb-input"
placeholder= "USERNAME_PLACEHOLDER" name="username” onBlur={[Function]}
onChange={[Function]} onDragStart={[Function]} onDrop={[Function]}
onFocus={[Function]}
value="" />
Test examples
it('Empty value on initial state', () => {
expect(wrapper.find(
'input[name="username"]').value).toEqual('');
});
it('Placeholder is rendered', () => {
expect(wrapper.find('input[name="username"]')
.prop('placeholder'))
.toEqual('USERNAME_PLACEHOLDER');
});
GrandParadePoland
www.grandparade.co.uk
Rendered component (wrapper)
<input
id="reg-username"
type="text"
className="sb-input"
placeholder= "USERNAME_PLACEHOLDER"
name="username"
onBlur={[Function}
onChange={[Function]}
onDragStart={[Function]}
onDrop={[Function]}
onFocus={[Function]}
value="" />
Test examples
it('Username has less then minimum number of characters',() => {
wrapper.find('input[name="username"]')
.simulate('change', { target: { value: 'abcde' } })
.simulate('blur');
expect(wrapper.find('.sb-input-error').text())
.toEqual('USERNAME_ERROR_MIN_LENGTH');
});
it('Username has minimum number of characters',() => {
wrapper.find('input[name="username"]')
.simulate('change', { target: { value: 'abcdef' } })
.simulate('blur');
expect(wrapper.find('.sb-input-error').length).toEqual(0);
});
GrandParadePoland
www.grandparade.co.uk
Test examples – cleaning from hardcoded values ☺
it('CSF-38.AC04.02 Validation: negative minimum',() => {
wrapper.find('input[name="username"]')
.simulate('change', { target: { value: 'abcde' } })
.simulate('blur');
expect(wrapper.find('.sb-input-error').text())
.toEqual('USERNAME_ERROR_MIN_LENGTH');
});
it(testDesc.acceptance(testDesc.validation(`negative minimum (${fields.username.min
- 1})`), ticket, 'AC04', '02'), () => {
wrapper.find(fields.username.cssSelector)
.simulate('change', { target: { value: getUsers.username.invalidMin } })
.simulate('blur');
verifyError(wrapper, fields.username, baseErrors.min);
});
GrandParadePoland
www.grandparade.co.uk
Data Driven Testing
Recommended tools for Jest
○ jest-in-case
○ Sazerac
Jest-in-case
○ Cases function
○ Data Object
○ Results
○ More than DDT
GrandParadePoland
www.grandparade.co.uk
Snapshot tests – how it works
it('renders correctly', () => {
const tree = renderer.create(<Link page="http://www.facebook.com">Facebook</Link>)
.toJSON();
expect(tree).toMatchSnapshot();
});});
exports[`renders correctly 1`] = `
<a className="normal"
href="http://www.facebook.com"
onMouseEnter={[Function]}
onMouseLeave={[Function]} > Facebook </a>
`;
GrandParadePoland
www.grandparade.co.uk
Test
Snapshot
Snapshot tests
● Easy testing in some cases, typical examples:
○ renders of React.js components
○ other serializable data
● Generated when component is ready (not for TDD)
● Code coverage works with snapshots
● Updated on demand
● Need mocks if data in component changing
● Significantly slower than typical unit and component tests
● Stored in code repository (may increase repo size)
GrandParadePoland
www.grandparade.co.uk
Reporting and timescale
GrandParadePoland
www.grandparade.co.uk
Jest - reporting
Console
IntelliJ and WebStorm
Allure – local HTML reportand Jenkinsplugin
GrandParadePoland
www.grandparade.co.uk
Tests in CI
Gitlab Pipelines
● Automated start (push, merge)
● Easy parallelization
● Bock git actions when tests fail
● Configurable
● Job as code approach
GrandParadePoland
www.grandparade.co.uk
Tests in CI – Jenkins - integration with E2E
Jenkins
● Jobs / Multijob
● Allure plugin
GrandParadePoland
www.grandparade.co.uk
Timescale
Remarks
• execution time from Jenkins jobs, tests run parallel as Jenkins jobs
• Old – Java, cucumber, selenium
• New – JS, unit, component, integration - enzyme, E2E – webdriver.io
GrandParadePoland
www.grandparade.co.uk
Old - E2E New - component
Unit 1 min. 2 min.
Component - 2 min.
Integration 2 min. 1 min.
E2E > 55 min. approx. 10-15 min
Total > 55 min. approx. 10-15 min
How about test pyramid?
GrandParadePoland
www.grandparade.co.uk
Summary
GrandParadePoland
www.grandparade.co.uk
GrandParadePoland
www.grandparade.co.uk
Pros & Cons of our approach
Advantages
• Tests are less time consuming
• Stability of tests are much better
• Automated testing can be started earlier in
software developmentlife cycle
• QAs better understand how software works
internally – more opportunities to create good
test cases
Disadvantages
• Requires good cooperationand help from
developmentteam
• QAs have to adapt to developers’workflow and
projectrules
• Some tools have poordocumentation
• Some features in test tools are not mature yet
Questions?
GrandParadePoland
www.grandparade.co.uk
End

Weitere ähnliche Inhalte

Was ist angesagt?

Testing untestable Code - PFCongres 2010
Testing untestable Code - PFCongres 2010Testing untestable Code - PFCongres 2010
Testing untestable Code - PFCongres 2010Stephan Hochdörfer
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratiehcderaad
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETBen Hall
 
Ruby onrails cucumber-rspec-capybara
Ruby onrails cucumber-rspec-capybaraRuby onrails cucumber-rspec-capybara
Ruby onrails cucumber-rspec-capybaraBindesh Vijayan
 
Offline Strategies for HTML5 Web Applications - oscon13
Offline Strategies for HTML5 Web Applications - oscon13Offline Strategies for HTML5 Web Applications - oscon13
Offline Strategies for HTML5 Web Applications - oscon13Stephan Hochdörfer
 
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinMarvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinJava User Group Latvia
 
How Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran MizrahiHow Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran MizrahiRan Mizrahi
 
JUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by exampleJUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by exampleGeoffrey De Smet
 
Ditching jQuery Madison
Ditching jQuery MadisonDitching jQuery Madison
Ditching jQuery MadisonHao Luo
 
Automated Frontend Testing
Automated Frontend TestingAutomated Frontend Testing
Automated Frontend TestingNeil Crosby
 
The Screenplay Pattern: Better Interactions for Better Automation
The Screenplay Pattern: Better Interactions for Better AutomationThe Screenplay Pattern: Better Interactions for Better Automation
The Screenplay Pattern: Better Interactions for Better AutomationApplitools
 
@IndeedEng: Tokens and Millicents - technical challenges in launching Indeed...
@IndeedEng:  Tokens and Millicents - technical challenges in launching Indeed...@IndeedEng:  Tokens and Millicents - technical challenges in launching Indeed...
@IndeedEng: Tokens and Millicents - technical challenges in launching Indeed...indeedeng
 
Intro to TDD and BDD
Intro to TDD and BDDIntro to TDD and BDD
Intro to TDD and BDDJason Noble
 
5 ways to embrace HTML5 today
5 ways to embrace HTML5 today5 ways to embrace HTML5 today
5 ways to embrace HTML5 todayDaniel Ryan
 
Efficient Django
Efficient DjangoEfficient Django
Efficient DjangoDavid Arcos
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideMek Srunyu Stittri
 
PostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performancePostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performanceVladimir Sitnikov
 
Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Chris Ramsdale
 
Migration testing framework
Migration testing frameworkMigration testing framework
Migration testing frameworkIndicThreads
 

Was ist angesagt? (20)

Testing untestable Code - PFCongres 2010
Testing untestable Code - PFCongres 2010Testing untestable Code - PFCongres 2010
Testing untestable Code - PFCongres 2010
 
2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie2014 11 20 Drupal 7 -> 8 test migratie
2014 11 20 Drupal 7 -> 8 test migratie
 
Testing ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NETTesting ASP.NET - Progressive.NET
Testing ASP.NET - Progressive.NET
 
Ruby onrails cucumber-rspec-capybara
Ruby onrails cucumber-rspec-capybaraRuby onrails cucumber-rspec-capybara
Ruby onrails cucumber-rspec-capybara
 
Offline Strategies for HTML5 Web Applications - oscon13
Offline Strategies for HTML5 Web Applications - oscon13Offline Strategies for HTML5 Web Applications - oscon13
Offline Strategies for HTML5 Web Applications - oscon13
 
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey BuzdinMarvel of Annotation Preprocessing in Java by Alexey Buzdin
Marvel of Annotation Preprocessing in Java by Alexey Buzdin
 
How Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran MizrahiHow Testability Inspires AngularJS Design / Ran Mizrahi
How Testability Inspires AngularJS Design / Ran Mizrahi
 
JUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by exampleJUDCon London 2011 - Bin packing with drools planner by example
JUDCon London 2011 - Bin packing with drools planner by example
 
Ditching jQuery Madison
Ditching jQuery MadisonDitching jQuery Madison
Ditching jQuery Madison
 
Automated Frontend Testing
Automated Frontend TestingAutomated Frontend Testing
Automated Frontend Testing
 
The Screenplay Pattern: Better Interactions for Better Automation
The Screenplay Pattern: Better Interactions for Better AutomationThe Screenplay Pattern: Better Interactions for Better Automation
The Screenplay Pattern: Better Interactions for Better Automation
 
@IndeedEng: Tokens and Millicents - technical challenges in launching Indeed...
@IndeedEng:  Tokens and Millicents - technical challenges in launching Indeed...@IndeedEng:  Tokens and Millicents - technical challenges in launching Indeed...
@IndeedEng: Tokens and Millicents - technical challenges in launching Indeed...
 
Intro to TDD and BDD
Intro to TDD and BDDIntro to TDD and BDD
Intro to TDD and BDD
 
5 ways to embrace HTML5 today
5 ways to embrace HTML5 today5 ways to embrace HTML5 today
5 ways to embrace HTML5 today
 
Efficient Django
Efficient DjangoEfficient Django
Efficient Django
 
Node.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java sideNode.js and Selenium Webdriver, a journey from the Java side
Node.js and Selenium Webdriver, a journey from the Java side
 
PostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performancePostgreSQL and JDBC: striving for high performance
PostgreSQL and JDBC: striving for high performance
 
Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010Building Web Apps Sanely - EclipseCon 2010
Building Web Apps Sanely - EclipseCon 2010
 
Migration testing framework
Migration testing frameworkMigration testing framework
Migration testing framework
 
Android dev 3
Android dev 3Android dev 3
Android dev 3
 

Ähnlich wie KraQA #29 - Component level testing of react app, using enzyme

Intro To Django
Intro To DjangoIntro To Django
Intro To DjangoUdi Bauman
 
Automated Performance Testing With J Meter And Maven
Automated  Performance  Testing With  J Meter And  MavenAutomated  Performance  Testing With  J Meter And  Maven
Automated Performance Testing With J Meter And MavenPerconaPerformance
 
Rapid Application Development with WSO2 Platform
Rapid Application Development with WSO2 PlatformRapid Application Development with WSO2 Platform
Rapid Application Development with WSO2 PlatformWSO2
 
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fastHow Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fastAtlassian
 
Test strategy for web development
Test strategy for web developmentTest strategy for web development
Test strategy for web developmentalice yang
 
OWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA TestersOWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA TestersJavan Rasokat
 
Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018Holger Grosse-Plankermann
 
Creando microservicios con Java, Microprofile y TomEE - Baranquilla JUG
Creando microservicios con Java, Microprofile y TomEE - Baranquilla JUGCreando microservicios con Java, Microprofile y TomEE - Baranquilla JUG
Creando microservicios con Java, Microprofile y TomEE - Baranquilla JUGCésar Hernández
 
Automated acceptance test
Automated acceptance testAutomated acceptance test
Automated acceptance testBryan Liu
 
Testing Web Applications
Testing Web ApplicationsTesting Web Applications
Testing Web ApplicationsSeth McLaughlin
 
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Das Frontend richtig Testen – mit Jest @Developer Week 2018Das Frontend richtig Testen – mit Jest @Developer Week 2018
Das Frontend richtig Testen – mit Jest @Developer Week 2018Holger Grosse-Plankermann
 
Test strategies for data processing pipelines, v2.0
Test strategies for data processing pipelines, v2.0Test strategies for data processing pipelines, v2.0
Test strategies for data processing pipelines, v2.0Lars Albertsson
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGuillaume Laforge
 
Migration strategies 4
Migration strategies 4Migration strategies 4
Migration strategies 4Wenhua Wang
 
Choosing a Javascript Framework
Choosing a Javascript FrameworkChoosing a Javascript Framework
Choosing a Javascript FrameworkAll Things Open
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit TestingKeir Bowden
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiRan Mizrahi
 

Ähnlich wie KraQA #29 - Component level testing of react app, using enzyme (20)

Intro To Django
Intro To DjangoIntro To Django
Intro To Django
 
Automated Performance Testing With J Meter And Maven
Automated  Performance  Testing With  J Meter And  MavenAutomated  Performance  Testing With  J Meter And  Maven
Automated Performance Testing With J Meter And Maven
 
Rapid Application Development with WSO2 Platform
Rapid Application Development with WSO2 PlatformRapid Application Development with WSO2 Platform
Rapid Application Development with WSO2 Platform
 
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fastHow Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
 
Test strategy for web development
Test strategy for web developmentTest strategy for web development
Test strategy for web development
 
OWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA TestersOWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA Testers
 
Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018Jest: Frontend Testing leicht gemacht @EnterJS2018
Jest: Frontend Testing leicht gemacht @EnterJS2018
 
Creando microservicios con Java, Microprofile y TomEE - Baranquilla JUG
Creando microservicios con Java, Microprofile y TomEE - Baranquilla JUGCreando microservicios con Java, Microprofile y TomEE - Baranquilla JUG
Creando microservicios con Java, Microprofile y TomEE - Baranquilla JUG
 
Automated acceptance test
Automated acceptance testAutomated acceptance test
Automated acceptance test
 
Testing Web Applications
Testing Web ApplicationsTesting Web Applications
Testing Web Applications
 
Das Frontend richtig Testen – mit Jest @Developer Week 2018
Das Frontend richtig Testen – mit Jest @Developer Week 2018Das Frontend richtig Testen – mit Jest @Developer Week 2018
Das Frontend richtig Testen – mit Jest @Developer Week 2018
 
Test strategies for data processing pipelines, v2.0
Test strategies for data processing pipelines, v2.0Test strategies for data processing pipelines, v2.0
Test strategies for data processing pipelines, v2.0
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
 
PARTHA MAITY
PARTHA MAITYPARTHA MAITY
PARTHA MAITY
 
Droidcon Paris 2015
Droidcon Paris 2015Droidcon Paris 2015
Droidcon Paris 2015
 
Migration strategies 4
Migration strategies 4Migration strategies 4
Migration strategies 4
 
Choosing a Javascript Framework
Choosing a Javascript FrameworkChoosing a Javascript Framework
Choosing a Javascript Framework
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
Intro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran MizrahiIntro To JavaScript Unit Testing - Ran Mizrahi
Intro To JavaScript Unit Testing - Ran Mizrahi
 

Mehr von kraqa

RestAssured w sluzbie testow API
RestAssured w sluzbie testow APIRestAssured w sluzbie testow API
RestAssured w sluzbie testow APIkraqa
 
Postman - podstawy testowania REST API
Postman - podstawy testowania REST APIPostman - podstawy testowania REST API
Postman - podstawy testowania REST APIkraqa
 
Stanislaw potoczny kra_qa_21.01.20
Stanislaw potoczny kra_qa_21.01.20Stanislaw potoczny kra_qa_21.01.20
Stanislaw potoczny kra_qa_21.01.20kraqa
 
Machine learning powered regression - KraQA 42 - Pawel Dyrek
Machine learning powered regression - KraQA 42 - Pawel Dyrek Machine learning powered regression - KraQA 42 - Pawel Dyrek
Machine learning powered regression - KraQA 42 - Pawel Dyrek kraqa
 
Kontrakt testy - KraQA 42 - Slawomir Radzyminski
Kontrakt testy - KraQA 42 - Slawomir RadzyminskiKontrakt testy - KraQA 42 - Slawomir Radzyminski
Kontrakt testy - KraQA 42 - Slawomir Radzyminskikraqa
 
KraQA#41 - PageFactory
KraQA#41 - PageFactoryKraQA#41 - PageFactory
KraQA#41 - PageFactorykraqa
 
KraQA#39 - Jak testowac tool do testow
KraQA#39 - Jak testowac tool do testowKraQA#39 - Jak testowac tool do testow
KraQA#39 - Jak testowac tool do testowkraqa
 
Hyperion - wystarczy jeden shake
Hyperion - wystarczy jeden shakeHyperion - wystarczy jeden shake
Hyperion - wystarczy jeden shakekraqa
 
Wybor urzadzen mobilnych do testow
Wybor urzadzen mobilnych do testowWybor urzadzen mobilnych do testow
Wybor urzadzen mobilnych do testowkraqa
 
Continuous security
Continuous securityContinuous security
Continuous securitykraqa
 
Let s meet inside
Let s meet insideLet s meet inside
Let s meet insidekraqa
 
O wezu przy kawie
O wezu przy kawieO wezu przy kawie
O wezu przy kawiekraqa
 
Strategia do automatów
Strategia do automatówStrategia do automatów
Strategia do automatówkraqa
 
Z czym do api
Z czym do apiZ czym do api
Z czym do apikraqa
 
Jenkins pipelines
Jenkins pipelinesJenkins pipelines
Jenkins pipelineskraqa
 
Testy UI
Testy UITesty UI
Testy UIkraqa
 
Tester w pułapce myślenia
Tester w pułapce myśleniaTester w pułapce myślenia
Tester w pułapce myśleniakraqa
 
Kiedy tester zostaje managerem
Kiedy tester zostaje manageremKiedy tester zostaje managerem
Kiedy tester zostaje manageremkraqa
 
KraQA#32 - RODO
KraQA#32 - RODOKraQA#32 - RODO
KraQA#32 - RODOkraqa
 
SkładQA 2018 - Daniel Dec
SkładQA 2018 - Daniel DecSkładQA 2018 - Daniel Dec
SkładQA 2018 - Daniel Deckraqa
 

Mehr von kraqa (20)

RestAssured w sluzbie testow API
RestAssured w sluzbie testow APIRestAssured w sluzbie testow API
RestAssured w sluzbie testow API
 
Postman - podstawy testowania REST API
Postman - podstawy testowania REST APIPostman - podstawy testowania REST API
Postman - podstawy testowania REST API
 
Stanislaw potoczny kra_qa_21.01.20
Stanislaw potoczny kra_qa_21.01.20Stanislaw potoczny kra_qa_21.01.20
Stanislaw potoczny kra_qa_21.01.20
 
Machine learning powered regression - KraQA 42 - Pawel Dyrek
Machine learning powered regression - KraQA 42 - Pawel Dyrek Machine learning powered regression - KraQA 42 - Pawel Dyrek
Machine learning powered regression - KraQA 42 - Pawel Dyrek
 
Kontrakt testy - KraQA 42 - Slawomir Radzyminski
Kontrakt testy - KraQA 42 - Slawomir RadzyminskiKontrakt testy - KraQA 42 - Slawomir Radzyminski
Kontrakt testy - KraQA 42 - Slawomir Radzyminski
 
KraQA#41 - PageFactory
KraQA#41 - PageFactoryKraQA#41 - PageFactory
KraQA#41 - PageFactory
 
KraQA#39 - Jak testowac tool do testow
KraQA#39 - Jak testowac tool do testowKraQA#39 - Jak testowac tool do testow
KraQA#39 - Jak testowac tool do testow
 
Hyperion - wystarczy jeden shake
Hyperion - wystarczy jeden shakeHyperion - wystarczy jeden shake
Hyperion - wystarczy jeden shake
 
Wybor urzadzen mobilnych do testow
Wybor urzadzen mobilnych do testowWybor urzadzen mobilnych do testow
Wybor urzadzen mobilnych do testow
 
Continuous security
Continuous securityContinuous security
Continuous security
 
Let s meet inside
Let s meet insideLet s meet inside
Let s meet inside
 
O wezu przy kawie
O wezu przy kawieO wezu przy kawie
O wezu przy kawie
 
Strategia do automatów
Strategia do automatówStrategia do automatów
Strategia do automatów
 
Z czym do api
Z czym do apiZ czym do api
Z czym do api
 
Jenkins pipelines
Jenkins pipelinesJenkins pipelines
Jenkins pipelines
 
Testy UI
Testy UITesty UI
Testy UI
 
Tester w pułapce myślenia
Tester w pułapce myśleniaTester w pułapce myślenia
Tester w pułapce myślenia
 
Kiedy tester zostaje managerem
Kiedy tester zostaje manageremKiedy tester zostaje managerem
Kiedy tester zostaje managerem
 
KraQA#32 - RODO
KraQA#32 - RODOKraQA#32 - RODO
KraQA#32 - RODO
 
SkładQA 2018 - Daniel Dec
SkładQA 2018 - Daniel DecSkładQA 2018 - Daniel Dec
SkładQA 2018 - Daniel Dec
 

Kürzlich hochgeladen

『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书rnrncn29
 
NSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationNSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationMarko4394
 
Q4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxQ4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxeditsforyah
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predieusebiomeyer
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书zdzoqco
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa494f574xmv
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxDyna Gilbert
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Sonam Pathan
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhimiss dipika
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Sonam Pathan
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationLinaWolf1
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书rnrncn29
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作ys8omjxb
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Paul Calvano
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一z xss
 

Kürzlich hochgeladen (17)

『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
『澳洲文凭』买拉筹伯大学毕业证书成绩单办理澳洲LTU文凭学位证书
 
NSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentationNSX-T and Service Interfaces presentation
NSX-T and Service Interfaces presentation
 
Q4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptxQ4-1-Illustrating-Hypothesis-Testing.pptx
Q4-1-Illustrating-Hypothesis-Testing.pptx
 
SCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is prediSCM Symposium PPT Format Customer loyalty is predi
SCM Symposium PPT Format Customer loyalty is predi
 
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
办理多伦多大学毕业证成绩单|购买加拿大UTSG文凭证书
 
Film cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasaFilm cover research (1).pptxsdasdasdasdasdasa
Film cover research (1).pptxsdasdasdasdasdasa
 
Top 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptxTop 10 Interactive Website Design Trends in 2024.pptx
Top 10 Interactive Website Design Trends in 2024.pptx
 
Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170Call Girls Near The Suryaa Hotel New Delhi 9873777170
Call Girls Near The Suryaa Hotel New Delhi 9873777170
 
Contact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New DelhiContact Rya Baby for Call Girls New Delhi
Contact Rya Baby for Call Girls New Delhi
 
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in  Rk Puram 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Rk Puram 🔝 9953056974 🔝 Delhi escort Service
 
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
Call Girls In The Ocean Pearl Retreat Hotel New Delhi 9873777170
 
PHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 DocumentationPHP-based rendering of TYPO3 Documentation
PHP-based rendering of TYPO3 Documentation
 
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
『澳洲文凭』买詹姆士库克大学毕业证书成绩单办理澳洲JCU文凭学位证书
 
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
Potsdam FH学位证,波茨坦应用技术大学毕业证书1:1制作
 
Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24Font Performance - NYC WebPerf Meetup April '24
Font Performance - NYC WebPerf Meetup April '24
 
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
young call girls in Uttam Nagar🔝 9953056974 🔝 Delhi escort Service
 
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
办理(UofR毕业证书)罗切斯特大学毕业证成绩单原版一比一
 

KraQA #29 - Component level testing of react app, using enzyme

  • 1. GrandParadePoland www.grandparade.co.uk Component level testing of react app, using enzyme KraQA – 23.01.2018 Wojciech Czyżycki, Senior QA Engineer Tomasz Suwaj, QA Engineer Grand Parade, Central Services FrontEnd Team
  • 2. Agenda ●Company & Project ○ About GP & WH ●Test approach ○ Agile@Scale transformation ○ Detecting vs Preventing bugs, testing earlier in lifecycle ●Testing in React.JS project ○ Main ideas & tools ○ Enzyme ■ introduction ■ DOMtesting - render, shallow, mount ■ Selectors, find, user actions simulation ○ DDT& Snapshots, ○ Reporting, timing, statistics ●Summary ○ Pros & cons of this solution GrandParadePoland www.grandparade.co.uk
  • 4. GrandParade ● Founded in 2007 ● UK: London, PL: Kraków ● Products: apps,websites and commerce platforms forthe sports,gaming and media companies ● Acquisitionby WH in 2016 ● Number of employees:~ 300 About company - GP GrandParadePoland www.grandparade.co.uk
  • 5. About company - WH GrandParadePoland www.grandparade.co.uk WilliamHill ● Founded in 1934 ● Leading betting company ○ Retail ○ Online ■ Sports ■ Gaming ● UK, Gibraltar, Poland, Bulgaria, Italy, Spain, USA, Australia and the Philippines ● Number of employees:~16k
  • 6. About project • Registration application • About 20 WH sites on desktop • Banners, landing pages,promotions • Bonus actions • Analytics • Challenges • Technologicalconsistency • Customization by CMS • Multi-step • Field order • Componentversions • Tests inCucumber/Selenium/Java GrandParadePoland www.grandparade.co.uk
  • 8. Agile@Scale transformation What are we doing • Scrum as default managementframework • Reducing silos and building cross functionalteams • Productcentred teams • Putting trust (and responsibility) into teams • High level of test automation – coverage 80-90% (code and functional) • CI/CD processimprovements GrandParadePoland www.grandparade.co.uk
  • 9. Test approach - Detecting bugs Traditionalapproach • QA silos – weak collaboration • Late testing – usually after deployon test environment • Often lack of time to create automated tests Results • Low test code quality (lack of patterns) • Slow and flaky E2E tests • Low trust to automated tests results • More and more manual work GrandParadePoland www.grandparade.co.uk
  • 11. Preventing bugs Currentapproach • Environment equippedwith tools for early testing • QAs work close with developers,shared quality responsibility • QA tests in dev project,obligatory codereview • Automated test pipeline on push and merge Results • Early bug/inconsistencyidentification • Better test code quality • Very fast and stable componenttests • High functional requirements coverage by automation • Huge reductionof E2E test GrandParadePoland www.grandparade.co.uk High cost Low speed Low cost High speed Exploratory testing
  • 12. Tools ● JavaScript ES6 + Babel ● Npm, yarn – package managers ● React.js – front-end framework ● Enzyme – testing tool for React.js ● JSDOM – headless browser ● Jest – test runner, assertion library, spy tool, optimized for React.js ● Mocha/Chai/Sinon – tools replaced by Jest ● Gitlab – code management tool, CI pipelines ● Allure – test report generator GrandParadePoland www.grandparade.co.uk
  • 13. Project structure ● Tests in component directory ● Unit, component, integration tests in the same directory ● Test mocks, helpers, user data generators, DDT data in separate common directory ● E2E tests in separate project GrandParadePoland www.grandparade.co.uk
  • 14. Testing in React.JS project GrandParadePoland www.grandparade.co.uk
  • 15. How React works • Components – Componentis an object that encapsulates part of the app. Reusable and easy to test. • Reactivity – Elements are rendered after every change • Virtual DOM(DocumentObject Model) – Abstractequivalent of DOM, used to detect (by comparision) which elements have changed and need to be re-rendered • JSX – Allows to pass JS objects into HTML, e.g. <div> <ObjectJS /> </ div> GrandParadePoland www.grandparade.co.uk
  • 16. Enzyme – what it is? Enzyme is a JavaScript Testing utility forReact that makes it easier to render, assert and manipulate your React Components' output. Enzyme – Airbnb projectwith more than 200 contributors Decentdocumentationbut very general, with very basic examples http://airbnb.io/enzyme/ GrandParadePoland www.grandparade.co.uk
  • 17. Enzyme – DOM testing Shallow • Don't render children • Isolated - test cannot affecteach other • Faster than Mount Render • Renders Static HTML structure • With children Mount • Renders full DOM • Includes the logic of components • Testcan affecteach other GrandParadePoland www.grandparade.co.uk
  • 18. .find() <input type="text" id="reg-firstName" class="sb-input sb-input--error" placeholder="" name="firstName" value=""> Supported CSS Selectors ID element = wrapper.find('#reg-firstName'); Class Name element = wrapper.find('.sb-input'); Atribute element = wrapper.find('[name="firstName"]'); Elementtype element = wrapper.find('input[name="firstName"]'); Contextual element = wrapper.find('input.sb-input'); element = wrapper.find(('#reg-firstName > .sb-input-error'); GrandParadePoland www.grandparade.co.uk
  • 19. .find() Not Supported Selectors Pseudo Class element = wrapper.find('input:not([disabled])'); Enzyme received a pseudo-class CSS selector ('input:not([disabled])') that it does not currently support Xpath element = wrapper.find('//*[@id="reg-firstName"]'); Supported getters elements.first() elements.last() elements.at(n) – n-th element Usage example: element2 = wrapper.find('.sb-input').at(1) GrandParadePoland www.grandparade.co.uk
  • 20. .simulate() .simulate('focus') .simulate('blur') .simulate('click') .simulate('change', { target: { value: 'New value' }}) When to use change? • change dropdownvalue • check/uncheckcheckbox When to use click? • click on button • click on clickable span GrandParadePoland www.grandparade.co.uk
  • 21. Jest assertions examples .toBe() expect(someBoolean).toBe(true); .toEqual() expect('chicken').toEqual('chicken'); expect(number).toEqual(5); .toContain() expect('fried chicken').toContain('chicken'); .toBeGreaterThan() expect(100).toBeGreaterThan(99) GrandParadePoland www.grandparade.co.uk
  • 22. Test examples describe('Username field tests', () => { beforeEach(() => { wrapper = mount( <Component {...props} /> ); }); it('Not a test, just console log',() => { input = wrapper.find('#reg-firstName'); console.log(input.debug()); }); }); GrandParadePoland www.grandparade.co.uk Props Example const props = { name: 'username', hintText:'USERNAME_HINT', placeholder:'USERNAME_PLACEHOLDER', ... }
  • 23. GrandParadePoland www.grandparade.co.uk .debug() vs HTML in browser <input id="reg-username" type="text" className="sb-input" placeholder= "USERNAME_PLACEHOLDER" name="username” onBlur={[Function]} onChange={[Function]} onDragStart={[Function]} onDrop={[Function]} onFocus={[Function]} value="" />
  • 24. Test examples it('Empty value on initial state', () => { expect(wrapper.find( 'input[name="username"]').value).toEqual(''); }); it('Placeholder is rendered', () => { expect(wrapper.find('input[name="username"]') .prop('placeholder')) .toEqual('USERNAME_PLACEHOLDER'); }); GrandParadePoland www.grandparade.co.uk Rendered component (wrapper) <input id="reg-username" type="text" className="sb-input" placeholder= "USERNAME_PLACEHOLDER" name="username" onBlur={[Function} onChange={[Function]} onDragStart={[Function]} onDrop={[Function]} onFocus={[Function]} value="" />
  • 25. Test examples it('Username has less then minimum number of characters',() => { wrapper.find('input[name="username"]') .simulate('change', { target: { value: 'abcde' } }) .simulate('blur'); expect(wrapper.find('.sb-input-error').text()) .toEqual('USERNAME_ERROR_MIN_LENGTH'); }); it('Username has minimum number of characters',() => { wrapper.find('input[name="username"]') .simulate('change', { target: { value: 'abcdef' } }) .simulate('blur'); expect(wrapper.find('.sb-input-error').length).toEqual(0); }); GrandParadePoland www.grandparade.co.uk
  • 26. Test examples – cleaning from hardcoded values ☺ it('CSF-38.AC04.02 Validation: negative minimum',() => { wrapper.find('input[name="username"]') .simulate('change', { target: { value: 'abcde' } }) .simulate('blur'); expect(wrapper.find('.sb-input-error').text()) .toEqual('USERNAME_ERROR_MIN_LENGTH'); }); it(testDesc.acceptance(testDesc.validation(`negative minimum (${fields.username.min - 1})`), ticket, 'AC04', '02'), () => { wrapper.find(fields.username.cssSelector) .simulate('change', { target: { value: getUsers.username.invalidMin } }) .simulate('blur'); verifyError(wrapper, fields.username, baseErrors.min); }); GrandParadePoland www.grandparade.co.uk
  • 27. Data Driven Testing Recommended tools for Jest ○ jest-in-case ○ Sazerac Jest-in-case ○ Cases function ○ Data Object ○ Results ○ More than DDT GrandParadePoland www.grandparade.co.uk
  • 28. Snapshot tests – how it works it('renders correctly', () => { const tree = renderer.create(<Link page="http://www.facebook.com">Facebook</Link>) .toJSON(); expect(tree).toMatchSnapshot(); });}); exports[`renders correctly 1`] = ` <a className="normal" href="http://www.facebook.com" onMouseEnter={[Function]} onMouseLeave={[Function]} > Facebook </a> `; GrandParadePoland www.grandparade.co.uk Test Snapshot
  • 29. Snapshot tests ● Easy testing in some cases, typical examples: ○ renders of React.js components ○ other serializable data ● Generated when component is ready (not for TDD) ● Code coverage works with snapshots ● Updated on demand ● Need mocks if data in component changing ● Significantly slower than typical unit and component tests ● Stored in code repository (may increase repo size) GrandParadePoland www.grandparade.co.uk
  • 31. Jest - reporting Console IntelliJ and WebStorm Allure – local HTML reportand Jenkinsplugin GrandParadePoland www.grandparade.co.uk
  • 32. Tests in CI Gitlab Pipelines ● Automated start (push, merge) ● Easy parallelization ● Bock git actions when tests fail ● Configurable ● Job as code approach GrandParadePoland www.grandparade.co.uk
  • 33. Tests in CI – Jenkins - integration with E2E Jenkins ● Jobs / Multijob ● Allure plugin GrandParadePoland www.grandparade.co.uk
  • 34. Timescale Remarks • execution time from Jenkins jobs, tests run parallel as Jenkins jobs • Old – Java, cucumber, selenium • New – JS, unit, component, integration - enzyme, E2E – webdriver.io GrandParadePoland www.grandparade.co.uk Old - E2E New - component Unit 1 min. 2 min. Component - 2 min. Integration 2 min. 1 min. E2E > 55 min. approx. 10-15 min Total > 55 min. approx. 10-15 min
  • 35. How about test pyramid? GrandParadePoland www.grandparade.co.uk
  • 37. GrandParadePoland www.grandparade.co.uk Pros & Cons of our approach Advantages • Tests are less time consuming • Stability of tests are much better • Automated testing can be started earlier in software developmentlife cycle • QAs better understand how software works internally – more opportunities to create good test cases Disadvantages • Requires good cooperationand help from developmentteam • QAs have to adapt to developers’workflow and projectrules • Some tools have poordocumentation • Some features in test tools are not mature yet
  • 39. End