Top Banner
1 CONFIDENTIAL Andrew Winder Senior Software Engineer, Message Systems Testing Javascript with Mocha and Friends 5/22/22
13

Testing Javascript Apps with Mocha and Chai

Jun 22, 2015

Download

Technology

Andrew Winder

Testing code is very important and leads to more well-thought-out designs and more stable codebases. But how do we test javascript applications? Tools like Sinon.js, Mocha, and Chai can alleviate some of the pain as we try to bring testing benefits into our applications
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Testing Javascript Apps with Mocha and Chai

1

CONFIDENTIAL

Andrew WinderSenior Software Engineer, Message Systems

Testing Javascript with Mocha and Friends

April 13, 2023

Page 2: Testing Javascript Apps with Mocha and Chai

2

Why Testing?

Page 3: Testing Javascript Apps with Mocha and Chai

3

What is a test?

expect(something).to.equal(something)

Page 4: Testing Javascript Apps with Mocha and Chai

4

What is a test?

expect(something).to.equal(something)

The Subject

Page 5: Testing Javascript Apps with Mocha and Chai

5

What is a test?

expect(something).to.equal(something)

The Assertion

Page 6: Testing Javascript Apps with Mocha and Chai

6

What Kind of Testing?

Page 7: Testing Javascript Apps with Mocha and Chai

7

How to test Javascript?

Page 8: Testing Javascript Apps with Mocha and Chai

8

Simple Unit Testing

Page 9: Testing Javascript Apps with Mocha and Chai

9

What about Async?

Page 10: Testing Javascript Apps with Mocha and Chai

10

What about Async?

Page 11: Testing Javascript Apps with Mocha and Chai

11

Mocking with Sinon & Proxyquire

• Use Mocks in unit testing for:• Stability• Speed• Accuracy

• Proxyquire for Mock Injection• Sinon for creating Mocks

Page 12: Testing Javascript Apps with Mocha and Chai

12

Example of ProxyQuire & Sinon.JS

Page 13: Testing Javascript Apps with Mocha and Chai

13

Demo & QuestionsTwitter: @awinder

[email protected]