A
Behavior
is an isolated set of DOM / user interactions that can be mixed into anyView
or anotherBehavior
.
Behaviors allow you to blackbox
View
-specific interactions into portable logical chunks, keeping your Views simple and your code DRY.
Explanations and implementation details were perfectly presented by Stéphane Bachelier at Backbone.js Paris S01E06
const Alert = Marionette.Behavior.extend( {
defaults: {
title: "Alert!",
message: "Not really urgent"
},
events: {
"click": "emitAlert"
},
emitAlert() {
alert( this.options.message );
}
} );
it( "should emit an alert", () => {
// => This won't work
expect( Behavior.emitAlert() ).toEmitAnAlert();
} );
To test a Behavior independently from a view:
Testing the Behavior-View interaction in every views tests suite…