Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Blog - Testing Marionette.js Behaviors - behavior test factory with context
function addOnClickTests ( context ) {
let model, view, behavior, options;
beforeEach( () => {
model = new context.ModelClass();
view = new context.ViewClass( { model: model } );
// Retrieve instantiated behavior and its actual options under this context.
behavior = _.findWhere( view._behaviors, { id: "addOnClick" } );
options = behavior.options;
model.set( options.propertyToIncrease, 1 );
} );
it( "should be instantiated", () => {
expect( behavior ).not.toBeUndefined( );
} );
it( "should increase the model value when we click on the view", () => {
var expectedValue = model.get( options.propertyToIncrease ) + options.increaseStep;
view.$el.trigger( "click" );
expect( model.get( options.propertyToIncrease ) ).toBe( expectedValue );
} );
}
const OnClick = Marionette.Behavior.extend( {
id: "addOnClick",
defaults: {
propertyToIncrease: "size",
increaseStep: 1
},
events: {
"click": "add"
},
add() {
// increase `propertyToIncrease` by `increaseStep`
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.