Skip to content

Instantly share code, notes, and snippets.

View sonicoder86's full-sized avatar

Gábor Soós sonicoder86

View GitHub Profile
import React from "react";
import { useSearchParams } from "next/navigation";
import type { PropsWithChildren } from "react";
import { z } from "zod";
const MAIN_PAGE = "main";
const VIDEOS_PAGE = "videos";
const pageDefinitions = {
import { z } from 'zod'
const MAIN_PAGE = 'main'
const VIDEOS_PAGE = 'videos'
const pages = [MAIN_PAGE, VIDEOS_PAGE] as const
type Page = typeof pages[number]
const pageDefinitions = {
@sonicoder86
sonicoder86 / index.js
Created February 1, 2021 18:21
Write Vue like you write React - part 2
import { defineComponent, ref, watchEffect } from 'vue';
export const Counter = defineComponent({
props: ['limit', 'onLimit'],
setup(props) {
const count = ref(0);
const handler = () => count.value++;
watchEffect(
() => (count.value >= props.limit) ? props.onLimit() : null
@sonicoder86
sonicoder86 / index.jsx
Created February 1, 2021 18:20
Write Vue like you write React - part 1
import { useState, useEffect } from 'react';
export const Counter = ({ limit, onLimit }) => {
const [count, setCount] = useState(0);
const handler = () => setCount(count + 1);
useEffect(
() => (count >= limit) ? onLimit() : null,
[count]
);
@sonicoder86
sonicoder86 / e2e.spec.js
Last active July 22, 2020 16:22
Svelte 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 July 22, 2020 16:21
Svelte 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'
}));
const { store, onModify } = createStore();
let info;
store.subscribe(value => info = value);
await onModify('Modified by click');
@sonicoder86
sonicoder86 / store.js
Created July 22, 2020 16:21
Svelte Testing Crash Course - part 13
return {
store,
async onModify(info) {
const response = await axios.post('https://example.com/api', { info });
store.update(() => response.body);
}
};
@sonicoder86
sonicoder86 / jest.config.js
Created July 22, 2020 16:20
Svelte Testing Crash Course - part 12
module.exports = {
transform: {
'^.+\\.js$': 'babel-jest',
'^.+\\.svelte$': 'svelte-jester'
},
transformIgnorePatterns: [
"node_modules/(?!(svelte-routing|svelte-spa-router)/)"
]
};
@sonicoder86
sonicoder86 / router.spec.js
Created July 22, 2020 16:20
Svelte Testing Crash Course - part 11
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');
@sonicoder86
sonicoder86 / routing.svelte
Created July 22, 2020 16:18
Svelte Testing Crash Course - part 10
<script>
import { Router, Route } from 'svelte-routing';
import Footer from './component-display.svelte';
</script>
<Router>
<Route path="/"><Footer /></Route>
</Router>