This file contains 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
<script> | |
import { useState } from './state'; | |
export default { | |
setup() { | |
return { state: useState() }; | |
} | |
}; | |
</script> |
This file contains 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 { 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'); |
This file contains 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 { 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() | |
); |
This file contains 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
<template> | |
<div>{{ state.counter }}</div> | |
<button type="button" @click="state.counter++">Increment</button> | |
</template> | |
<script> | |
import { reactive } from 'vue'; | |
export default { | |
setup() { |
This file contains 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 { reactive } from 'vue'; | |
export const state = reactive({ counter: 0 }); |
This file contains 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('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'); | |
}); |
This file contains 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
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' }); | |
}); |
This file contains 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 onModify = async ({ commit }, info) => { | |
const response = await axios.post('https://example.com/api', { info }); | |
commit('modify', { info: response.body }); | |
}; |
This file contains 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 { 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( |
This file contains 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 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 ( |