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 { createElement, createContext, useReducer, useContext } from "react"; | |
const Context = createContext(); | |
export const ContextProvider = Context.Provider; | |
export const useStore = (reducer, initialState = {}) => { | |
const [state, dispatch] = useReducer(reducer, initialState); | |
const getState = () => state; |
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
exports[`Snapshot tests work with arrays 1`] = ` | |
Array [ | |
"a", | |
5, | |
[Function], | |
] | |
`; | |
exports[`Snapshot tests work with objects 1`] = ` | |
Object { |
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('Snapshot tests', () => { | |
it('work with objects', () => { | |
expect({ | |
a: 234, | |
b: 'test', | |
c: null, | |
d: undefined, | |
}).toMatchSnapshot(); | |
}); |
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
exports[`The BuyNow component renders the right price and button 1`] = ` | |
<div> | |
<span | |
className="price"> | |
£ | |
25 | |
</span> | |
<button | |
className="btn-primary"> | |
Buy now |
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
// BuyNow.test.jsx | |
import { shallow } from 'enzyme'; | |
import toJson from 'enzyme-to-json'; | |
import BuyNow from '../BuyNow'; | |
describe('The BuyNow component', () => { | |
it('renders the right price and button', () => { | |
const props = { price: 25, text: 'Buy now' }; | |
const tree = shallow(<BuyNow {...props} />); |
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
// BuyNow.jsx | |
const BuyNow = ({ price, text }) => (<div> | |
<span className="price">£{price}</span> | |
<button className="btn-primary">{text}</button> | |
</div>); | |
// BuyNow.test.jsx | |
import { shallow } from 'enzyme'; | |
import BuyNow from '../BuyNow'; |
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 handler from '../handler'; | |
import expectedUserJson from '../mocks/user'; | |
describe('the user handler', () => { | |
it('returns the user information given its id', () => { | |
const response = handler('35409DJFJ48'); | |
expect(response).toEqual(expectedUserJson); | |
}); | |
}); |
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 { parseDate } from '..'; | |
describe('parseDate', () => { | |
it('parses a Date object', () => { | |
const expectedResult = { | |
day: 13, | |
month: 2, | |
year: 2017 | |
}; | |
const result = parseDate(2017, 1, 13); |
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
export function parseDate (date) { | |
return { | |
day: date.getDate(), | |
month: date.getMonth() + 1, | |
year: date.getFullYear() | |
}; | |
} |
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 path = require('path'); | |
const merge = require('webpack-merge'); | |
const devConfig = require('./webpack.dev.config'); | |
const prodConfig = require('./webpack.prod.config'); | |
var config; | |
const common = { | |
entry: { |
NewerOlder