Presentation is loading. Please wait.

Presentation is loading. Please wait.

Zero to Testing in JavaScript Basics of testing in JS.

Similar presentations


Presentation on theme: "Zero to Testing in JavaScript Basics of testing in JS."— Presentation transcript:

1 Zero to Testing in JavaScript Basics of testing in JS

2 About me Software developer for Xfinity.com Online: thewebivore.com, @pamasaur Co-organizer of Philadelphia JavaScript Developers Testing fanatic

3 Agenda My testing story Writing your first JavaScript test Testing frameworks Working testing into your workflow

4 My testing story

5 My Testing Story Code Retreat TDD Pairing Throw-away code Testing at work Now: test coverage drops break the build

6 What’s the deal with testing? When you break it, it breaks! Secondary line of documentation defense Design tool

7 What do you call code without tests? Legacy code.

8 Testing front-end code The debt in your /js folder Front-end code has logic too! If you have logic, you need tests

9 BDD/TDD Behavior Driven Development Test-Driven Development “Write tests to inform how you write your code” BDD: Describe, it, before, after, beforeEach, afterEach TDD: Suite, test, setup, teardown

10 Test Ever vs. Test Never

11 Writing your first JavaScript test

12 Setting up your base Writing the test* Making it pass* * The order of these is debatable

13 Jasmine jasmine.github.io Download a standalone version on GitHub from pivotal/jasminepivotal/jasmine Or use RubyGems for a Ruby environment

14 Mocha visionmedia.github.io/mocha Node! npm install –g mocha

15 Anatomy of a test Describe [thing you’re testing] It [does something you expect it to do] Rinse and repeat.

16 Example test walk-through with Mocha

17 var assert = require('assert'); describe("An area of my application", function() { it("should know that 2 and 2 is 4", function(){ assert.equal(4, 2+2); });

18

19

20

21

22

23 Testing concepts: Unit testing Test your code

24 Spies, stubs, and mocks Spy: an object that records its interactions Stubs: fake objects Mocks: fake objects with expected behavior Generally, you can SPY on a function, STUB an object, and MOCK a service.

25 Live coding? Write a test with me!

26 Testing Tools

27 Test describers Jasmine Mocha QUnit node-tap YUI Test

28 Assertions Chai should.js Expect.js better-assert

29 Spies, stubs, and mocks Sinon.js Jest from Facebook Jest

30 Test runners Karma Teaspoon YUI Yeti

31 Bringing testing into the fold 3 tips for making testing a regular part of your world

32 #1: Teach testing Attend talks like this! Practice (ex. Code Retreat) Pair programming

33 #2: Code coverage Istanbul Blanket.js hrcov (Mozilla) JSCover

34 #3: Code review Quality assurance Mentoring Don’t accept without tests!

35 What’d we learn? Writing a JavaScript test Tools in JavaScript for testing Ways to create a testing culture

36 Thank you! Find me online at @pamasaur thewebivore.com (blog) turing.cool (podcast) bleedingedgepress.com (upcoming book on JS frameworks)


Download ppt "Zero to Testing in JavaScript Basics of testing in JS."

Similar presentations


Ads by Google