Skip to content

Instantly share code, notes, and snippets.

import { forOwn, reduce, isPlainObject } from 'lodash';
function validateConfig(config) {
if (!isPlainObject(config)) {
throw new Error('config must be plain object');
} else if (!isPlainObject(config.storeKeys)) {
throw new Error('storeKeys must be plain object');
}
}
@kloy
kloy / ez.js
Created January 15, 2016 04:04
Simpler API for testing react components
import _ from 'lodash';
import ReactTestUtils from 'react-addons-test-utils';
import { findDOMNode } from 'react-dom';
import { renderToStaticMarkup } from 'react-dom/server';
import reactElementToJSXString from 'react-element-to-jsx-string';
import collapse from 'collapse-white-space';
import shallowQuery from 'react-shallow-query';
let ez = {};
@kloy
kloy / unit-bootstrap.js
Created January 15, 2016 03:52
Karma + webpack alias
/* global TEST_FILE,TEST_DIRECTORY */
'use strict'; // eslint-disable-line
require('./test-app');
if (TEST_DIRECTORY !== '') {
const testsContext = require.context('TEST_DIRECTORY', true);
testsContext.keys().forEach(testsContext);
} else if (TEST_FILE !== '') {
require('TEST_FILE'); // using webpack alias here so TEST_FILE must be a string
QUnit.test('should update folders list when a new folder is created', assert => {
assert.expect(3);
const done = assert.async();
const data = fixtures.createSuccessResponse('foo');
server.respondWith(
'POST',
'/test/folders/',
[
200, // status code
'should change isLoading when matters fetched'.test(() => {
mockStore.dispatch(actions.fetchMatters({
route: 'matters',
initial: true,
}));
mockPromises.tick();
expect(mockStore.getState().mattersView).toEqual({
...mattersViewFixture,
fetchStates: 'LOADING',
@kloy
kloy / mixin.js
Created September 21, 2015 20:33
function applyMixin(targetPrototype, obj) {
function applyProperty(prop, value) {
let descriptor = Object.getOwnPropertyDescriptor(targetPrototype, prop);
// Avoid setting properties that are not writable
if (descriptor && !descriptor.writable) {
return;
}
Object.defineProperty(targetPrototype, prop, {
@kloy
kloy / di.spec.js
Created September 13, 2015 15:43
ES2016 Dependency Injector strategies
import { expect } from './testHelpers';
let injector = {
_items: new Map(),
singleton(name, Value) {
const inst = new Value();
this._items.set(name, inst);
},
value(name, value) {
this._items.set(name, value);
<?php
// in application/routes.php
Route::post('user', function()
{
$data = array('userId' => 1);
return Response::make(json_encode($data), 200,
array('Content-Type' => 'application/json'));
});
Route::get('user', function()
<?php
// features/bootstrap/RestContext.php
use Behat\Behat\Context\BehatContext;
use Symfony\Component\Yaml\Yaml;
/**
* Rest context.
*/
class RestContext extends BehatContext
{
<?php
// features/bootstrap/FeatureContext.php testing-rest-api-with-behat/FeatureContext.php
use Behat\Behat\Context\ClosuredContextInterface,
Behat\Behat\Context\TranslatedContextInterface,
Behat\Behat\Context\BehatContext,
Behat\Behat\Exception\PendingException;
use Behat\Gherkin\Node\PyStringNode,
Behat\Gherkin\Node\TableNode;
//