Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="mocha"></div>
              
            
!

CSS

              
                
              
            
!

JS

              
                mocha.setup('bdd')
var expect = chai.expect;
var h = maquette.h;
var exports = {};

// Complete sourcecode from maquette-query 0.6.3 (This can be collapsed)
(function(){
// Helper functions
// ----------------
var makeSelectorFunction = function (selector) {
    if (typeof selector === 'string') {
        return function (vNode) {
            var index = vNode.vnodeSelector.indexOf(selector);
            if ((selector[0] === '.' || selector[0] === '#') ? (index > 0) : (index === 0)) {
                var nextChar = vNode.vnodeSelector.charAt(index + selector.length);
                return !nextChar || nextChar === '.' || nextChar === '#';
            }
            return false;
        };
    }
    else if (typeof selector === 'function') {
        return selector;
    }
    else {
        throw new Error('Invalid selector ' + selector);
    }
};
var filterDescendants = function (root, predicate) {
    var results = [];
    var visit = function (vnodeTree) {
        if (vnodeTree.children) {
            vnodeTree.children.forEach(function (child) {
                if (predicate(child)) {
                    results.push(child);
                }
                visit(child);
            });
        }
    };
    visit(root);
    return results;
};
// Simulator
var collectTextContent = function (vnodeTree, results) {
    if (vnodeTree.vnodeSelector === '') {
        results.push(vnodeTree.text);
    }
    else {
        if (vnodeTree.text) {
            results.push(vnodeTree.text);
        }
        if (vnodeTree.children) {
            vnodeTree.children.forEach(function (child) {
                collectTextContent(child, results);
            });
        }
    }
    return results;
};
var createEvent = function (target) {
    var result = {
        defaultPrevented: false,
        propagationStopped: false,
        preventDefault: function () {
            result.defaultPrevented = true;
        },
        stopPropagation: function () {
            result.propagationStopped = true;
        },
        target: target,
        currentTarget: target
    };
    return result;
};
var createKeyEvent = function (which, target) {
    var event = createEvent(target);
    event.which = which;
    event.keyCode = which;
    return event;
};
var createMouseEvent = function (target, parameters) {
    var event = createEvent(target);
    if (parameters) {
        event.pageX = parameters.pageX;
        event.pageY = parameters.pageY;
    }
    return event;
};
var createFocusEvent = function (target) {
    return createEvent(target);
};
var getKeyCode = function (keyCodeOrChar) {
    return typeof keyCodeOrChar === 'number' ? keyCodeOrChar : keyCodeOrChar.charCodeAt(0);
};
var createSimulator = function (vnode, defaultFakeDomNode) {
    var properties = vnode.properties;
    return {
        keyDown: function (keyCode, fakeDomNode) {
            var event = createKeyEvent(getKeyCode(keyCode), fakeDomNode || defaultFakeDomNode);
            properties.onkeydown(event);
            return event;
        },
        keyUp: function (keyCode, fakeDomNode) {
            var event = createKeyEvent(getKeyCode(keyCode), fakeDomNode || defaultFakeDomNode);
            properties.onkeyup(event);
            return event;
        },
        mouseDown: function (fakeDomNode, parameters) {
            var event = createMouseEvent(fakeDomNode || defaultFakeDomNode, parameters);
            properties.onmousedown(event);
            return event;
        },
        mouseUp: function (fakeDomNode, parameters) {
            var event = createMouseEvent(fakeDomNode || defaultFakeDomNode, parameters);
            properties.onmouseup(event);
            return event;
        },
        click: function (fakeDomNode, parameters) {
            var event = createMouseEvent(fakeDomNode || defaultFakeDomNode, parameters);
            properties.onclick(event);
            return event;
        },
        input: function (fakeDomNode) {
            var event = createEvent(fakeDomNode || defaultFakeDomNode);
            properties.oninput(event);
            return event;
        },
        change: function (fakeDomNode) {
            var event = createEvent(fakeDomNode || defaultFakeDomNode);
            properties.onchange(event);
            return event;
        },
        focus: function (fakeDomNode) {
            var event = createFocusEvent(fakeDomNode || defaultFakeDomNode);
            properties.onfocus(event);
            return event;
        },
        blur: function (fakeDomNode) {
            var event = createFocusEvent(fakeDomNode || defaultFakeDomNode);
            properties.onblur(event);
            return event;
        },
        keyPress: function (keyCodeOrChar, valueBefore, valueAfter, fakeDomNode) {
            var target = (fakeDomNode || defaultFakeDomNode || {});
            var keyCode = typeof keyCodeOrChar === 'number' ? keyCodeOrChar : keyCodeOrChar.charCodeAt(0);
            target.value = valueBefore;
            if (properties.onkeydown) {
                properties.onkeydown(createKeyEvent(keyCode, target));
            }
            target.value = valueAfter;
            if (properties.onkeyup) {
                properties.onkeyup(createKeyEvent(keyCode, target));
            }
            if (properties.oninput) {
                properties.oninput(createEvent(target));
            }
        }
    };
};
// The create methods
var createCollectionQuery;
var createQuery = function (getVNode) {
    var query = function (selector, fakeDomNode) {
        var predicate = makeSelectorFunction(selector);
        return createQuery(function () { return filterDescendants(getVNode(), predicate)[0]; });
    };
    var queryAll = function (selector) {
        var predicate = makeSelectorFunction(selector);
        return createCollectionQuery(function () { return filterDescendants(getVNode(), predicate); });
    };
    var getResult = function () {
        var result = getVNode();
        if (!result) {
            throw new Error('Query did not match a VNode');
        }
        return result;
    };
    var targetDomNode;
    return {
        execute: getResult,
        exists: function () { return !!getVNode(); },
        query: query,
        queryAll: queryAll,
        get textContent() {
            return collectTextContent(getResult(), []).join('');
        },
        get vnodeSelector() {
            return getResult().vnodeSelector;
        },
        get properties() {
            return getResult().properties;
        },
        get children() {
            return getResult().children;
        },
        getChild: function (index) {
            return createQuery(function () {
                return getResult().children[index];
            });
        },
        /**
         * A small facade that allows firing of simple events and sequences of events for common usecases.
         * It is not meant to be exhaustive.
         * If you need to simulate something that is not in here, you can simply invoke query(...).properties.on???() yourself.
         */
        get simulate() { return createSimulator(getResult(), targetDomNode); },
        setTargetDomNode: function (target) {
            targetDomNode = target;
        },
        getTargetDomNode: function () {
            return targetDomNode;
        }
    };
};
createCollectionQuery = function (getVNodes) {
    return {
        execute: getVNodes,
        getResult: function (index) {
            return createQuery(function () {
                return getVNodes()[index];
            });
        },
        get length() {
            return getVNodes().length;
        }
    };
};
/**
 * Creates a test projector which implements the Query interface
 * @param renderMaquetteFunction The renderMaquette function that is used to produce the VNode tree.
 * Optional, when not specified, you must use the initialize function to supply the renderMaquetteFunction.
 */
exports.createTestProjector = function (renderMaquetteFunction) {
    var createVNode = function () {
        if (!renderMaquetteFunction) {
            throw new Error('TestProjector was not initialized');
        }
        return renderMaquetteFunction();
    };
    var initialize = function (initializeRenderMaquetteFunction) {
        renderMaquetteFunction = initializeRenderMaquetteFunction;
    };
    var result = createQuery(createVNode);
    result.initialize = initialize;
    return result;
};

//# sourceMappingURL=index.js.map
  
}());

// Creates a button component
function createMyButton(text, onClick) {
  var handleClick = function(evt) {
    evt.preventDefault();
    onClick();
  };

  var myButton = {
    renderMaquette: function() {
      return h("my-button", {key: myButton}, [ 
        h("button", { onclick: handleClick }, [text])
      ]);
    }
  };
  return myButton;
}

describe('myButton', function() {

  var projector = exports.createTestProjector(); // Special projector used in unit tests
  var myButtonComponent = undefined; // We create a fresh instance for each test in the beforeEach
  var button = projector.query('button'); // A query which will find the <button> element
  var clickHandler = sinon.stub(); 
  
  beforeEach(function() {
    clickHandler.reset();
    myButtonComponent = createMyButton('ButtonText', clickHandler);
    projector.initialize(myButtonComponent.renderMaquette);
  });

  it('displays the configured text', function() {
    expect(button.textContent).to.equal('ButtonText')
  });
  
  it('calls the handler when clicked', function() {
    button.simulate.click();
    expect(clickHandler.callCount).to.equal(1);
  });

});

mocha.run();

              
            
!
999px

Console