30
Randy Jones Jackie Roberts @randysjones @webdevjackie Unit Testing with the JavaScript API

Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

  • Upload
    others

  • View
    36

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Randy Jones Jackie Roberts@randysjones @webdevjackie

Unit Testing with the JavaScript API

Page 2: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

• A Lot of Demos• Tons of Tools

Last Year’s Talk

Page 3: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

This Year’s Talk

• Some Ground Rules• Start with TDD• Testing Frameworks• Legacy Application• Web AppBuilder

Page 4: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Write Code

Write Test

Write code, break test

Rewrite Test

How do we Test?

Page 5: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Write Test

Test Fails

Write code till passes

Refactor

Test Driven Development

Write Test

Test Fails

Write code till passes

Refactor

Test Driven Development

Page 6: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Rule #1:

Don’t Test Other People’s Code

Page 7: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Rule #2:

Prioritize

Page 8: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

https://www.slideshare.net/abagmar/anand-bagmar-behavior-driven-testing-bdt-in-agile

Page 9: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Nightmare Test Pyramid

Bugs

A single functional test thathasn’t passed in three years

Page 10: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Rule #3:EncapsulateEncapsulateEncapsulate

Page 11: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Easy to Test=

Easy to Maintain

Page 12: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Jackie starts next slide

Page 13: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

TestFromTheStartFlickr Photo by nostri-imago https://flic.kr/p/8XF4BL shared under a Creative Commons (BY) license

Page 14: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Can IReact?(or Angularor Emberor new-trendy-framework)

Flickr Photo by nostri-imago https://flic.kr/p/8XF4BL shared under a Creative Commons (BY) license

Page 15: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground
Page 16: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

https://jestjs.io/docs/en/getting-startedhttps://enzymejs.github.io/enzyme/

Can group related tests by wrapping them in describe(), or individually write tests using it() or test() blocks

expect() is a global function for making assertions

jest.fn() and expect(fn).toBeCalled() to create “spies” or mock functions

Page 17: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

FixYourLegacy

Flickr Photo by nostri-imago https://flic.kr/p/8XF4BL shared under a Creative Commons (BY) license

Page 18: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

https://github.com/Esri/enterprise-build-sample-js

Page 19: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

What About Web AppBuilder?

https://github.com/Esri/esri-wab-build

Page 20: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Separate Your Code

https://github.com/Esri/generator-esri-appbuilder-js

Web AppBuilderDev Edition

generate

watch Copywidget

git

create

Page 21: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

ArcGIS JS CLIhttps://github.com/Esri/arcgis-js-cli

Legacy App Samplehttps://github.com/Esri/enterprise-build-sample-js

Nearby App - Reacthttps://github.com/Esri/nearby-javascript

Web AppBuilder Resourceshttps://github.com/rsjones/wab-test-example

The Clean Code Talks -> Unit Testinghttps://www.youtube.com/watch?v=wEhu57pih5w

2018 Talk – Javascript Applications for the Enterprise: Test More, Work Lesshttps://www.youtube.com/watch?v=amEMQk5iY5c&t=8s

Resources

Page 22: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Using the ArcGIS API for JavaScript with Reacthttps://developers.arcgis.com/javascript/latest/guide/react/

esri-loaderhttps://developers.arcgis.com/javascript/latest/guide/esri-loader/index.html

Jesthttps://jestjs.io/docs/en/getting-started

Enzyme https://enzymejs.github.io/enzyme/

Resources

Page 23: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Intern – Test Runner & Frameworkhttps://theintern.io/

Karma – Test Runnerhttp://karma-runner.github.io/latest/index.html

SinonJS – Spies, Stubs, Mockshttps://sinonjs.org/

TS Mockito – Strongly Typed Mocking Libraryhttps://github.com/NagRock/ts-mockito

Jasmine – Test Frameworkhttps://jasmine.github.io/

Tooling

Page 24: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

• Section Subhead

Section Header

Page 25: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Related Talks - UPDATE

Web AppBuilder for ArcGIS: Advanced Development Tools and Techniques• TODAY // 5:30 – 6:30• Catalina / Medera• George Bochenek / Gavin Rehkemper

Page 26: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Download the EsriEvents app and find

your event

Select the session you attended

Scroll down to “Survey”

Log in to access the survey

Complete the survey and select “Submit”

Please Share Your Feedback in the App

Page 27: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Presenter Names

Presentation Title

Page 28: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground
Page 29: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Section SubheadSection Header

Page 30: Unit Testing with the JavaScript API · 2020-04-30 · Unit Testing with the JavaScript API •A Lot of Demos •Tons of Tools Last Year’s Talk. This Year’s Talk •Some Ground

Presenter(s)Demo Title