Skip to content

Instantly share code, notes, and snippets.

View nicoespeon's full-sized avatar

Nicolas Carlo nicoespeon

View GitHub Profile
@nicoespeon
nicoespeon / behavior-test.js
Created March 23, 2016 23:53
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" } );
@nicoespeon
nicoespeon / view-test.js
Created March 23, 2016 23:52
Blog - Testing Marionette.js Behaviors - use behavior test factory
describe( "Like View", () => {
const View = LikeView.extend( { template: _.template( "" ) } );
describe( "AddOnClick Behavior", () => {
addOnClickTests( { ViewClass: View, ModelClass: LikeModel } );
} );
@nicoespeon
nicoespeon / behavior-test.js
Created March 23, 2016 23:51
Blog - Testing Marionette.js Behaviors - behavior test factory
function addOnClickTests ( context ) {
let model, view;
beforeEach( () => {
model = new context.ModelClass();
view = new context.ViewClass( { model: model } );
} );
it( "should increase the model size by 1 when we click on the view", () => {
@nicoespeon
nicoespeon / test.js
Created March 23, 2016 23:50
Blog - Testing Marionette.js Behaviors - mock view test
describe( "Alert Behavior", () => {
let view;
beforeEach( () => {
view = Marionette.ItemView.extend( {
template: _.template( "" ),
behaviors: {
@nicoespeon
nicoespeon / view.js
Created March 23, 2016 23:49
Blog - Testing Marionette.js Behaviors - instantiated behavior
const ShareView = Marionette.ItemView.extend( {
template: "#card",
behaviors: {
AlertOnShare: {
behaviorClass: AlertBehavior,
title: "Shared",
message: "Your message has been shared!"
}
@nicoespeon
nicoespeon / behavior.js
Last active March 23, 2016 23:45
Blog - Testing Marionette.js Behaviors - problem
const Alert = Marionette.Behavior.extend( {
defaults: {
title: "Alert!",
message: "Not really urgent"
},
events: {
"click": "emitAlert"
},
@nicoespeon
nicoespeon / plopfile.js
Last active March 23, 2016 23:45
Blog - Plop — a micro-generator to ease your daily life - adapt actions to answers
module.exports = ( plop ) => {
plop.setGenerator( "module", {
prompts: [
{
type: "input",
name: "name",
message: "What is the name of your module?",
validate: isNotEmptyFor( "name" ),
@nicoespeon
nicoespeon / calendars.js
Last active March 23, 2016 23:46
Blog - Plop — a micro-generator to ease your daily life - calendars parsed
import Module from "core/module";
import _ from "lodash";
// IMPORT MODULE FILES
import Model from "./calendars.model";
const namespace = "calendars";
Model = Model.extend( { namespace: namespace } );
@nicoespeon
nicoespeon / calendars.js
Last active March 23, 2016 23:46
Blog - Plop — a micro-generator to ease your daily life - calendars
import Module from "core/module";
import _ from "lodash";
// IMPORT MODULE FILES
const namespace = "calendars";
export default Module.extend( {
initialize() {
@nicoespeon
nicoespeon / calendars.model.js
Last active March 23, 2016 23:47
Blog - Plop — a micro-generator to ease your daily life - calendars.model result
/**
* TODO - Describe what your model does.
*
* @class Calendars.Model
* @module Calendars
* @constructor
*/
import {Model} from "backbone";
export default Model.extend( {