Skip to content

Instantly share code, notes, and snippets.

View sonicoder86's full-sized avatar

Gábor Soós sonicoder86

View GitHub Profile
@sonicoder86
sonicoder86 / componennt.vue
Created July 14, 2020 08:00
You Might Not Need Vuex - part 5
<script>
import { useState } from './state';
export default {
setup() {
return { state: useState() };
}
};
</script>
@sonicoder86
sonicoder86 / app.js
Created July 14, 2020 07:59
You Might Not Need Vuex - part 4
import { createApp, reactive } from 'vue';
import App from './App.vue';
import { stateSymbol, createState } from './store';
const app = createApp(App);
app.provide(stateSymbol, createState());
app.mount('#app');
@sonicoder86
sonicoder86 / provide.js
Created July 14, 2020 07:57
You Might Not Need Vuex - part 3
import { reactive, provide, inject } from 'vue';
export const stateSymbol = Symbol('state');
export const createState = () => reactive({ counter: 0 });
export const useState = () => inject(stateSymbol);
export const provideState = () => provide(
stateSymbol,
createState()
);
@sonicoder86
sonicoder86 / component.vue
Created July 14, 2020 07:57
You Might Not Need Vuex - part 2
<template>
<div>{{ state.counter }}</div>
<button type="button" @click="state.counter++">Increment</button>
</template>
<script>
import { reactive } from 'vue';
export default {
setup() {
@sonicoder86
sonicoder86 / reactive.js
Created July 14, 2020 07:56
You Might Not Need Vuex - part 1
import { reactive } from 'vue';
export const state = reactive({ counter: 0 });
@sonicoder86
sonicoder86 / e2e.spec.js
Created April 15, 2020 18:28
React Testing Crash Course - part 16
describe('New todo', () => {
it('it should change info', () => {
cy.visit('/');
cy.contains('.info', 'Click to modify');
cy.get('button').click();
cy.contains('.info', 'Modified by click');
});
@sonicoder86
sonicoder86 / store.spec.js
Created April 15, 2020 18:27
React Testing Crash Course - part 15
it('should set info coming from endpoint', async () => {
const commit = jest.fn();
jest.spyOn(axios, 'post').mockImplementation(() => ({
body: 'Modified by post'
}));
await onModify({ commit }, 'Modified by click');
expect(commit).toHaveBeenCalledWith('modify', { info: 'Modified by post' });
});
@sonicoder86
sonicoder86 / store.js
Created April 15, 2020 18:26
React Testing Crash Course - part 14
const onModify = async ({ commit }, info) => {
const response = await axios.post('https://example.com/api', { info });
commit('modify', { info: response.body });
};
@sonicoder86
sonicoder86 / router.spec.js
Created April 15, 2020 18:26
React Testing Crash Course - part 13
import { Router } from 'react-router-dom';
import { createMemoryHistory } from 'history';
import { render } from '@testing-library/react';
describe('Routing', () => {
it('should display route', () => {
const history = createMemoryHistory();
history.push('/modify');
const { getByTestId } = render(
@sonicoder86
sonicoder86 / routing.js
Created April 15, 2020 18:25
React Testing Crash Course - part 12
import React from 'react';
import { withRouter } from 'react-router';
import { Route, Switch } from 'react-router-dom';
const Footer = withRouter(({ location }) => (
<div data-testid="location-display">{location.pathname}</div>
));
const App = () => {
return (