Skip to content

Instantly share code, notes, and snippets.

const increaseBy = makeActionCreator('INCREASE_BY')
import {increaseBy} from 'actions'
export const countReducer = makeReducer(increaseBy,
(state, {payload}) => state + payload,
{defaultState: 100}
)
const state1 = countReducer(undefined, {TYPE: '@@redux/INIT'})
// the initial state was set in defaultState and its value is 100
// ⇒ state1 === 100
const state2 = countReducer(state1, increaseBy(100))
// ⇒ state2 === 200
const state3 = countReducer(state2, increaseBy(-500))
// ⇒ state3 === -300
{
profile: {
data: undefined,
loading: false
},
customers: {
data: undefined,
loading: false
},
orders: {
{
profile: {
data: { id: '...', name: '...', /** ...user profile **/ },
loading: false
},
customers: {
data: [ 'customer0', 'customer1', /** ...customers array **/ ],
loading: false
},
orders: {
{
profile: {
data: null,
loading: false
},
customers: {
data: null,
loading: false
},
orders: {
describe('calculator', function() {
// describes a module with nested "describe" functions
describe('add', function() {
// specify the expected behavior
it('should add 2 numbers', function() {
//Use assertion functions to test the expected behavior
...
})
})
})
// Chai expect (popular)
expect(foo).to.be.a('string')
expect(foo).to.equal('bar')
// Jasmine expect (popular)
expect(foo).toBeString()
expect(foo).toEqual('bar')
// Chai assert
assert.typeOf(foo, 'string')
class Child {
...
execute(arg) { ... }
...
}
class Father {
constructor() {
this.child = new Child()
}
// make sure User.fetch to respond with a mocked user
// instead of making an actual ajax request
const stub = sinon
.stub(Users.prototype, 'fetch')
.resolves([
{ id: 0, name: 'David', score: 0 },
{ id: 1, name: 'Adam', score: 20 }
])
it('Should add score to a user', done => {