Skip to content

Instantly share code, notes, and snippets.

View alicekao's full-sized avatar

Alice Kao alicekao

  • San Francisco, CA
View GitHub Profile
@alicekao
alicekao / mockStore.js
Created August 17, 2016 18:41
How to mock store to test actions in a redux app
// Our action to fetch all places in actions/index.js
export function fetchPlaces() {
return dispatch => {
return axios.get('/api/places/fetchAll')
.then(resp => {
dispatch(updatePlaces(resp.data));
})
.catch(err => {
console.log('Couldn\'t fetch places: ', err);
dispatch(authError(err));
@alicekao
alicekao / axiosMockAdapterUse.js
Last active May 3, 2024 09:53
How to use axios mock adapter
// Fetch all places action to test in actions/index.js
import axios from 'axios';
export function fetchPlaces() {
return dispatch => {
return axios.get('/api/places/fetchAll')
.then(resp => {
dispatch(updatePlaces(resp.data));
})
.catch(err => {
@alicekao
alicekao / connectedComponents.js
Created August 17, 2016 17:48
Testing connected redux components
// Header component to test in header.js
import React, {Component} from 'react';
import { Link } from 'react-router';
export class Header extends Component { // Here we export our class
render() {
const { logoutUser } = this.props;
return (
@alicekao
alicekao / HeaderComponent.js
Last active August 17, 2016 17:51
Using enzyme to test react components
// Header component to test in header.js
import React, {Component} from 'react';
import { Link } from 'react-router';
export class Header extends Component {
render() {
const { logoutUser } = this.props;
return (