If you don’t test it, how do you know it works? Over the past few years, we have been compelled to write unit and integration tests for our applications--code that validates code--and it is these tests that change a one-off tool into a well-architected, robust, business-ready application. Yet, every new framework requires a new testing framework, so in this session, we will discuss testing frameworks for node.js. You will walk away with a solid understanding of how to write tests against your node.js applications and modules, leading to confidence that your work is business-ready.
15. “
TDD is to coding style as yoga is
to posture. Even when you're not
actively practicing, having done so
colors your whole life healthier.
”
j. kerr
21. $
node
test.js
assert.js:104
throw
new
assert.AssertionError({
^
AssertionError:
false
==
true
at
Object.<anonymous>
(my-‐test.js:7:8)
at
Module._compile
(module.js:449:26)
at
Object.Module._extensions..js
(module.js:467:10)
at
Module.load
(module.js:356:32)
at
Function.Module._load
(module.js:312:12)
at
Module.runMain
(module.js:487:10)
at
process.startup.processNextTick.process._tick...
$
_
31. $
node
my-‐test.js
assert.js:104
throw
new
assert.AssertionError({
^
AssertionError:
false
==
true
at
Object.<anonymous>
(my-‐test.js:7:8)
at
Module._compile
(module.js:449:26)
at
Object.Module._extensions..js
(module.js:467:10)
at
Module.load
(module.js:356:32)
at
Function.Module._load
(module.js:312:12)
at
Module.runMain
(module.js:487:10)
at
process.startup.processNextTick.process._tick...
$
_
39. $
mocha
-‐-‐ui
tdd
-‐-‐reporter
spec
Assertions
✓
should
pass
on
truthiness
1)
should
fail
on
falsiness
✖
1
of
2
tests
failed:
1)
Assertions
should
fail
on
falsiness:
AssertionError:
false
==
true
at
(stack
trace
omitted
for
brevity)
$
_
41. groupSyntax
suite('Testing
out
this
thing',
function()
{
suite('with
a
subset
of
this
other
thing',
function()
{
test('should
do
stuff',
function()
{
//
Assertion
tests
});
});
});
43. $
mocha
-‐-‐ui
tdd
-‐-‐reporter
spec
Assertions
of
truthiness
✓
should
pass
on
true
✓
should
pass
on
false
of
type
✓
should
pass
on
number
✔
3
tests
complete
(6ms)
$
_
45. pendingSyntax
suite('Testing
out
this
thing',
function()
{
suite('with
a
subset
of
this
other
thing',
function()
{
test('should
do
stuff
someday');
});
});
47. $
mocha
-‐-‐ui
tdd
-‐-‐reporter
spec
Assertions
of
truthiness
✓
should
pass
on
true
✓
should
pass
on
false
of
type
✓
should
pass
on
number
-‐
should
pass
on
object
✔
4
tests
complete
(6ms)
•
1
test
pending
$
_
61. $
make
test
Assertions
✓
should
pass
on
truthiness
1)
should
fail
on
falsiness
✖
1
of
2
tests
failed:
1)
Assertions
should
fail
on
falsiness:
AssertionError:
false
==
true
at
(stack
trace
omitted
for
brevity)
$
_
62. $
npm
test
Assertions
✓
should
pass
on
truthiness
1)
should
fail
on
falsiness
✖
1
of
2
tests
failed:
1)
Assertions
should
fail
on
falsiness:
AssertionError:
false
==
true
at
(stack
trace
omitted
for
brevity)
$
_
69. $
mocha
-‐-‐reporter
spec
-‐-‐slow
5
When
accessing
the
Ticket
API
with
valid
Morale
credentials,
and
with
a
project
that
exists,
getting
a
list
of
tickets
✓
should
return
without
an
error
✓
should
return
a
populated
array
(5ms)
✓
should
contain
a
task
or
bug
ticket
adding
a
new
ticket
✓
should
return
without
an
error
✓
should
return
the
new
ticket
(11ms)
✔
5
tests
complete
(22ms)
$
_
105. $
make
test
Assertions
of
truthiness
✓
should
pass
on
truthiness
✓
should
pass
on
falsiness
of
type
-‐
should
pass
on
number
-‐
should
pass
on
object
✔
4
tests
complete
(6ms)
•
2
test
pending
$
_