View
1.486
Download
5
Embed Size (px)
DESCRIPTION
Citation preview
Testing JavaScript
with Jasmine
Why should we test JavaScript?
How many times have you changed something in JavaScript
Only to break something else?
JavaScript = Production Code!
Which means, we need to treat it with respect
And, preserve the ability to
change
fix
clean
and refactor our JavaScript code
Without fear of breaking something
Testing is especially important when external factors can affect how our code functions
What makes a good test?
Think F.I.R.S.T
Fast
Independent
Tests should not depend on each other.
Repeatable
Always the same results, regardless of environment.
Self-Validating
Pass or FailNo manual evalutation.
Timely
Write tests before production code.
Let’s look at an example.
A random function for rolling a die.
What’s wrong here?
How do we normally debug JavaScript?
Let’s forget we even mentioned that…
So… we have this buggy code.
What do we do about it?
Write a failing test
Then Run the test to see it fail
SpecRunner.html
Squash the bug
Success!
Add more tests
Win!
Testing = Documentation!
Remember…
When you find yourself wanting to do this.
Write a test instead!
Questions?