TestING MARIONETTE.JS Behaviors

What is that, Behaviors?

> A Little check-up

From ze docs

A Behavior is an isolated set of DOM / user interactions that can be mixed into any View or another Behavior.

Behaviors allow you to blackbox View-specific interactions into portable logical chunks, keeping your Views simple and your code DRY.

Concretly

Explanations and implementation details were perfectly presented by Stéphane Bachelier at Backbone.js Paris S01E06

A pratical example

Testing your behaviors, just do it!

> problems

PB #1 : how to Test the API?

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();

} );

PB #2 : Coupling with the view

To test a Behavior independently from a view:

  • a lot of setup
  • no real value added
  • don't verify that Behavior-View actually works
    in the reality of our application

PB #3 : test code duplication

Testing the Behavior-View interaction in every views tests suite…

A PROPOSed Solution

Great articles about that

Thanks! Any question?

Made with Slides.com