Skip to content

Instantly share code, notes, and snippets.

@michelalbers
michelalbers / react-photoswipe.d.ts
Created November 22, 2018 14:25
react-photoswipe TypeScript typings
declare module 'react-photoswipe' {
import * as React from 'react';
export interface PhotoSwipeGalleryItem {
src: string;
thumbnail: string;
w: number;
h: number;
title: string;
}
@michelalbers
michelalbers / foo.component.tsx
Created September 21, 2018 13:34
Example Stateless Component with TypeScript
interface FooProps {
someProp: string;
someOtherProp: boolean;
}
const FooComponent: React.SFC<FooProps> = (props) => (
<div>Hello!</div>
);
class Example extends React.PureComponent<any, any> {
render() {
return (
<Query
query={getUsers}
>
{({ data, loading, error }) => {
// Do something with the user data
}}
</Query>
import * as React from 'react';
import * as renderer from 'react-test-renderer';
import MyComponent from '../MyComponent';
describe('<MyComponent />', () => {
it('should render without props', () => {
const json = renderer.create(<MyComponent />).toJSON();
expect(json).toMatchSnapshot();
});
});
@michelalbers
michelalbers / tsconfig.jest.json
Created September 9, 2018 19:02
Testing a GraphQL Next.js App with TypeScript and Apollo
{
"compilerOptions": {
"module": "commonjs",
"target": "esnext",
"jsx": "react",
"sourceMap": false,
"experimentalDecorators": true,
"noImplicitUseStrict": true,
"removeComments": false,
"moduleResolution": "node",
@michelalbers
michelalbers / jest.setup.js
Created September 9, 2018 18:59
Jest Setup file for testing a GraphQL Next.js App with TypeScript and Apollo
const enzyme = require('enzyme');
const Adapter = require('enzyme-adapter-react-16');
const config = require('./next.config');
const nextConfig = require('next/config');
enzyme.configure({ adapter: new Adapter() });
nextConfig.setConfig({
publicRuntimeConfig: {
IMAGE_SERVER_URL: 'http://images.foo.bar',
IMAGE_PROCESSOR_URL: 'https://processor.foo.bar',
@michelalbers
michelalbers / jest.config.js
Last active September 9, 2018 18:53
Testing a GraphQL Next.js App with TypeScript and Apollo
module.exports = {
setupFiles: ['<rootDir>/jest.setup.js'],
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/'],
transform: {
"^.+\\.tsx?$": "ts-jest",
},
testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
collectCoverageFrom: [
"**/*.{js,jsx,ts,tsx}",
"!**/_app.tsx",
@michelalbers
michelalbers / divide-spaced-values.css
Last active February 25, 2016 12:36
Divide spaced values in sass
.foo {
padding: 1px 1.5px;
}
" Pathogen
execute pathogen#infect()
" Basics
syntax on
filetype plugin indent on
set number
let mapleader = ","
set guifont=Menlo\ Regular:h13
@michelalbers
michelalbers / lib.menu.language.ts
Created January 21, 2015 19:14
Language Switcher in TYPO3 with tx_news support
lib.menuLanguage = COA
lib.menuLanguage {
10 = HMENU
10 {
special = language
special.value = 1,2
stdWrap.wrap = <ul class="language-select">|</ul>
1 = TMENU
1 {
# Normal link to language that exists: