Skip to content

Instantly share code, notes, and snippets.

View efalayi's full-sized avatar

Esther Falayi efalayi

View GitHub Profile
@efalayi
efalayi / Button.test.js
Created August 23, 2017 10:27
A simple test for button component
import React from 'react';
import renderer from 'react-test-renderer';
import { shallow } from 'enzyme';
import Button from '../components/Button.jsx';
describe('Button', () => {
const mockFn = jest.fn();
it('should be defined', () => {
expect(Button).toBeDefined();
});
@efalayi
efalayi / Button.test.js
Created August 23, 2017 10:37
A simple snapshot test for button component
import React from 'react';
import { shallow } from 'enzyme';
import Button from '../components/Button.jsx';
describe('Button', () => {
it('should be defined', () => {
expect(Button).toBeDefined();
});
it('should render correctly', () => {
const tree = shallow(
@efalayi
efalayi / setup.txt
Last active August 23, 2017 10:45
Jest and Enzyme installation
npm install jest enzyme --save-dev
@efalayi
efalayi / Button.test.js
Created August 23, 2017 10:51
Testing for button props
it('should have a button value', () => {
const tree = shallow(
<Button name='button test' />
);
expect(typeof(tree.find('.button').node.props.value)).toBe('string');
expect(tree.find('.button').node.props.value).toEqual('button test');
});
@efalayi
efalayi / Button.test.js
Created August 23, 2017 10:52
Testing a button click event
it('should call mock function when button is clicked', () => {
const tree = shallow(
<Button name='button test' handleClick={mockFn} />
);
tree.simulate('click');
expect(mockFn).toHaveBeenCalled();
});
@efalayi
efalayi / Button.jsx
Created August 23, 2017 11:01
Button component
import React from 'react';
/*
Button Component
@param {string} name
@param {func} handleClick
@returns button element
*/
const Button = ({ name, handleClick }) => {
return (
@efalayi
efalayi / methods.txt
Created August 23, 2017 11:07
Some handy Jest methods
jest.genMockFromModule(moduleName)
jest.mock(moduleName, factory, options)
jest.unmock(moduleName)
jest.dontMock(moduleName)
jest.clearAllMocks()
jest.resetAllMocks()
jest.setMock(moduleName, moduleExports)
jest.spyOn(object, methodName)
@efalayi
efalayi / webpack-boostrap.config.js
Created August 25, 2017 12:29
Bootstrap entry point
const fs = require('fs');
const getBootstraprcCustomLocation = () => {
return process.env.BOOTSTRAPRC_LOCATION;
};
const bootstraprcCustomLocation = getBootstraprcCustomLocation();
let defaultBootstraprcFileExists;
@efalayi
efalayi / font-awesome.config.js
Last active August 31, 2017 07:27
FontAwesome configuration for webpack
module.exports = {
// Default for the style loading
styleLoader: 'style-loader!css-loader!sass-loader',
styles: {
mixins: true,
'bordered-pulled': true,
core: true,
'fixed-width': true,
icons: true,
@efalayi
efalayi / webpack.sample.config.js
Last active January 25, 2018 23:58
Webpack config (sample)
const webpack = require('webpack');
const path = require('path');
const TransferWebpackPlugin = require('transfer-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
devtool: 'eval',
entry: [
'webpack/hot/only-dev-server',
'./client/app.jsx'