Skip to content

Instantly share code, notes, and snippets.

Avatar
🤩
Vue 3 streak

Gábor Soós blacksonic

🤩
Vue 3 streak
View GitHub Profile
@blacksonic
blacksonic / e2e.spec.js
Last active Jul 22, 2020
Svelte Testing Crash Course - part 16
View e2e.spec.js
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');
});
@blacksonic
blacksonic / store.spec.js
Created Jul 22, 2020
Svelte Testing Crash Course - part 15
View store.spec.js
it('should set info coming from endpoint', async () => {
const commit = jest.fn();
jest.spyOn(axios, 'post').mockImplementation(() => ({
body: 'Modified by post'
}));
const { store, onModify } = createStore();
let info;
store.subscribe(value => info = value);
await onModify('Modified by click');
@blacksonic
blacksonic / store.js
Created Jul 22, 2020
Svelte Testing Crash Course - part 13
View store.js
return {
store,
async onModify(info) {
const response = await axios.post('https://example.com/api', { info });
store.update(() => response.body);
}
};
@blacksonic
blacksonic / jest.config.js
Created Jul 22, 2020
Svelte Testing Crash Course - part 12
View jest.config.js
module.exports = {
transform: {
'^.+\\.js$': 'babel-jest',
'^.+\\.svelte$': 'svelte-jester'
},
transformIgnorePatterns: [
"node_modules/(?!(svelte-routing|svelte-spa-router)/)"
]
};
@blacksonic
blacksonic / router.spec.js
Created Jul 22, 2020
Svelte Testing Crash Course - part 11
View router.spec.js
import { render } from '@testing-library/svelte';
import Routing from './routing.svelte';
describe('Routing', () => {
it('should render routing', () => {
const { getByTestId } = render(Routing);
const element = getByTestId('info');
expect(element).toHaveTextContent('Click to modify');
@blacksonic
blacksonic / routing.svelte
Created Jul 22, 2020
Svelte Testing Crash Course - part 10
View routing.svelte
<script>
import { Router, Route } from 'svelte-routing';
import Footer from './component-display.svelte';
</script>
<Router>
<Route path="/"><Footer /></Route>
</Router>
@blacksonic
blacksonic / store.spec.js
Created Jul 22, 2020
Svelte Testing Crash Course - part 9
View store.spec.js
it('should modify state', () => {
const { store, onModify } = createStore();
let info;
store.subscribe(value => info = value);
onModify('Modified by click');
expect(info).toEqual('Modified by click');
});
@blacksonic
blacksonic / store.js
Created Jul 22, 2020
Svelte Testing Crash Course - part 8
View store.js
import { writable } from 'svelte/store';
export const createStore = () => {
const state = writable('Click to modify');
return {
state,
onModify(value) {
state.update(() => value);
}
@blacksonic
blacksonic / Footer.spec.js
Created Jul 22, 2020
Svelte Testing Crash Course - part 7
View Footer.spec.js
@blacksonic
blacksonic / Footer.svelte
Created Jul 22, 2020
Svelte Testing Crash Course - part 6
View Footer.svelte
You can’t perform that action at this time.