Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
rivets
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
9b3d6099
authored
2012-07-20 22:49:35 -0700
by
Michael Richards
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add initial set of tests for Rivets.Binding.
1 parent
5d8926e0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
0 deletions
spec/index.html
spec/rivets/binding.js
spec/index.html
View file @
9b3d609
...
...
@@ -13,6 +13,7 @@
<script
type=
"text/javascript"
src=
"matchers.js"
></script>
<script
type=
"text/javascript"
src=
"mock.data.js"
></script>
<script
type=
"text/javascript"
src=
"rivets/binding.js"
></script>
<script
type=
"text/javascript"
src=
"rivets.js"
></script>
<script
type=
"text/javascript"
>
...
...
spec/rivets/binding.js
0 → 100644
View file @
9b3d609
describe
(
'Rivets.Binding'
,
function
()
{
var
model
,
el
,
view
,
binding
;
beforeEach
(
function
()
{
rivets
.
configure
({
adapter
:
{
subscribe
:
function
()
{},
unsubscribe
:
function
()
{},
read
:
function
()
{},
publish
:
function
()
{}
}
});
el
=
document
.
createElement
(
'div'
);
el
.
setAttribute
(
'data-text'
,
'obj.name'
);
view
=
rivets
.
bind
(
el
,
{
obj
:
{}});
binding
=
view
.
bindings
[
0
];
});
it
(
'gets assigned the routine function matching the identifier'
,
function
()
{
expect
(
binding
.
routine
).
toBe
(
rivets
.
routines
.
text
);
});
describe
(
'set()'
,
function
()
{
it
(
'performs the binding routine with the supplied value'
,
function
()
{
spyOn
(
binding
,
'routine'
);
binding
.
set
(
'sweater'
);
expect
(
binding
.
routine
).
toHaveBeenCalledWith
(
el
,
'sweater'
);
});
it
(
'applies any formatters to the value before performing the routine'
,
function
()
{
rivets
.
config
.
formatters
=
{
awesome
:
function
(
value
)
{
return
'awesome '
+
value
}
};
binding
.
formatters
.
push
(
'awesome'
);
spyOn
(
binding
,
'routine'
);
binding
.
set
(
'sweater'
);
expect
(
binding
.
routine
).
toHaveBeenCalledWith
(
el
,
'awesome sweater'
);
});
describe
(
'on an event binding'
,
function
()
{
beforeEach
(
function
()
{
binding
.
bindType
=
'event'
;
});
it
(
'performs the binding routine with the supplied function and current listener'
,
function
()
{
spyOn
(
binding
,
'routine'
);
func
=
function
()
{
return
1
+
2
;
}
binding
.
set
(
func
);
expect
(
binding
.
routine
).
toHaveBeenCalledWith
(
el
,
func
,
undefined
);
});
it
(
'passes the previously set funcation as the current listener on subsequent calls'
,
function
()
{
spyOn
(
binding
,
'routine'
);
funca
=
function
()
{
return
1
+
2
;
};
funcb
=
function
()
{
return
2
+
5
;
};
binding
.
set
(
funca
);
expect
(
binding
.
routine
).
toHaveBeenCalledWith
(
el
,
funca
,
undefined
);
binding
.
set
(
funcb
);
expect
(
binding
.
routine
).
toHaveBeenCalledWith
(
el
,
funcb
,
funca
);
});
});
});
});
Please
register
or
sign in
to post a comment