This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const increaseBy = makeActionCreator('INCREASE_BY') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {increaseBy} from 'actions' | |
export const countReducer = makeReducer(increaseBy, | |
(state, {payload}) => state + payload, | |
{defaultState: 100} | |
) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
profile: { | |
data: undefined, | |
loading: false | |
}, | |
customers: { | |
data: undefined, | |
loading: false | |
}, | |
orders: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
profile: { | |
data: { id: '...', name: '...', /** ...user profile **/ }, | |
loading: false | |
}, | |
customers: { | |
data: [ 'customer0', 'customer1', /** ...customers array **/ ], | |
loading: false | |
}, | |
orders: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
profile: { | |
data: null, | |
loading: false | |
}, | |
customers: { | |
data: null, | |
loading: false | |
}, | |
orders: { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
... | |
}) | |
}) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Child { | |
... | |
execute(arg) { ... } | |
... | |
} | |
class Father { | |
constructor() { | |
this.child = new Child() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 => { |