![Show Menu](styles/mobile-menu.png)
![Page Background](./../common/page-substrates/page0289.png)
Superlists.Accounts.initialize is not a function
So let’s make it a function:
accounts/static/accounts.js.
window
.
Superlists
=
{
Accounts
:
{
initialize
:
function
() {}
}
};
And now we get a real test failure instead of just errors:
1. initialize binds sign in button to navigator.id.request (1, 0, 1)
1. failed
Expected: true
Result: false
Next—let’s separate defining our
initialize
function from the part where we export
it into the
Superlists
namespace. We’ll also do a
console.log
, which is the JavaScript
equivalent of a debug-print, to take a look at what the initialize function is being called
with:
accounts/static/accounts.js (ch15l028).
var
initialize
=
function
(
navigator
) {
console
.
log
(
navigator
);
};
window
.
Superlists
=
{
Accounts
:
{
initialize
:
initialize
}
};
In Firefox and I believe Chrome also, you can use the shortcut Ctrl-Shift-I to bring up
the JavaScript console, and see the [object Object] that was logged (see
Figure 15-4 ). If
you click on it, you can see it has the properties we defined in our test: an
id
, and inside
that, a function called
request
.
JavaScript Unit Tests Involving External Components: Our First Mocks!
|
261