Skip to content

Instantly share code, notes, and snippets.

View BrianJenney's full-sized avatar

jenneyb BrianJenney

View GitHub Profile
it('should show water bottles when a user navigates to `product/water-bottles`', () => {
const { findByText } = renderWithRouterMatch(
<ProductPage />,
{
path: '/:product',
route: '/water-bottles/'
},
{ store = {} }
);
const path = require('path');
const templatesPath = path.resolve(__dirname, 'templates'); // this is the path to our templates
const consumerPath = process.cwd(); // returns the current working directory
module.exports = (plop) => {
plop.setGenerator('component', componentPrompts({ templatesPath, consumerPath }));
};
module.exports = (plop) => {
require('component-generator-library')(plop);
};
@BrianJenney
BrianJenney / .babelrc
Created November 13, 2021 14:14
npm library starter
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": false
}
]
],
"plugins": ["@babel/plugin-transform-runtime"]
const Cart = ({items}) => {
const dispatch = useDispatch()
const isLoggedIn = useSelector((state) => state.account.isLoggedIn)
const clearCart = () => {
dispatch(reduxActionToClearCart())
}
if(!isLoggedIn){
const Cart = ({items, isLoggedIn, btnCallBack}) => {
if(!isLoggedIn){
return <LoginPrompt/>
}
return(
<div>
<div>
{items.map(({price, name}) => {
const ShoppingCart = () => {
const [errorMessage, setErrorMessage] = useState(null)
const isLoggedIn = useSelector((state) => state.account.isLoggedIn);
const urlToUse = isLoggedIn ? 'https://api/customercheckout' : 'https://api/guestcheckout';
const addToCartFunction = async (items) => {
const { data, errors } = await axios.post(urlToUse, {items});
if(errors){
import apiClient from './apiClient';
import ShoppingCart from './ShoppingCart';
const ShoppingCartContainer = ({apiClient}) => {
const [errorMessage, setErrorMessage] = useState(null)
const isLoggedIn = useSelector((state) => state.account.isLoggedIn);
const urlToUse = isLoggedIn ? 'https://api/customercheckout' : 'https://api/guestcheckout';
const addToCartFunction = async (items) => {
const axios = require('axios');
const flattenArr = (arr) => {
const retVal = [];
const helper = (val) => {
for (let i = 0; i < val.length; i++) {
if (Array.isArray(val[i])) {
helper(val[i]);
} else {
const { flattenArr, dataFetcher, createList } = require('./myFunc');
const axios = require('axios');
jest.mock('axios', () => ({
get: jest.fn(),
}));
describe.skip('flattenArr', () => {
it('return a non-nested arr', () => {
const input = [1, 2, 3, 4];