Skip to content

Instantly share code, notes, and snippets.

View janhesters's full-sized avatar
📈
Learning.

Jan Hesters janhesters

📈
Learning.
View GitHub Profile
@janhesters
janhesters / riteway-only.test.ts
Last active October 16, 2022 09:01
Vitest + RITEway
import { describe } from 'vitest';
import { assert } from './riteway';
describe('assert.only', () => {
assert({
given: 'this is a failing test',
should: 'be skipped because another test is here with .only',
actual: true,
expected: false,
// Some FP magic 🧙🏼‍♂️
const filter = (f, arr) => arr.filter(f);
const prop = key => obj => obj[key];
const getName = prop('name');
const strIncludes = query => str => str.includes(query);
const toLower = str => str.toLowerCase();
const pipe = (...fns) => x => fns.reduce((y, f) => f(y), x);
const nameIncludes = query =>
pipe(
getName,
#if ($ctx.error)
$util.appendError($ctx.error.message, $ctx.error.type, null, $ctx.result.data.unprocessedKeys)
#end
$util.toJson($ctx.result.data.Todo-dqxfzxnspvd3pf5facjmlgtsui-batch)
@janhesters
janhesters / example.yml
Created November 9, 2020 18:53
Our workflow.
name: Pull Request
on: [pull_request]
jobs:
unit-and-integration:
strategy:
fail-fast: false
matrix:
command:
// App.js
import Analytics from '@aws-amplify/analytics';
import Auth from '@aws-amplify/auth';
// ...
const mapObj = f => obj =>
Object.keys(obj).reduce((acc, key) => ({ ...acc, [key]: f(obj[key]) }), {});
const toArrayOfStrings = value => [`${value}`];
const mapToArrayOfStrings = mapObj(toArrayOfStrings);
async function trackUserId() {
@janhesters
janhesters / mock-fn.test.js
Created September 26, 2020 12:46
Tests for the mock fuction.
import { describe } from 'riteway';
import fn from './mock-fn.js';
describe('fn - the mock function', async assert => {
const mockedFn = fn((a, b) => a + b);
assert({
given: 'calling a mocked function',
should: 'should return the correct result',
@janhesters
janhesters / mock-fn.js
Created September 26, 2020 12:45
The mock function.
function fn(implementation = () => {}) {
const mockFn = (...args) => {
mockFn.calls.push(args);
return implementation(...args);
};
mockFn.calls = [];
return mockFn;
}
@janhesters
janhesters / table.md
Created September 26, 2020 12:45
Pros and cons of RITEway, RTL and E2E tests.
Tool Pros Cons
RITEway - runs the fastest (basically instant after Babel compiled) - good for pure components (map props to JSX) - good for other unit tests (reducers, sag
@janhesters
janhesters / home-page-container.js
Created September 26, 2020 12:43
Home page container.
import React, { useState } from 'react';
import HomePageComponent from './home-page-component.js';
function HomePage() {
const [count, setCount] = useState(0);
function handleIncrementClick() {
setCount(c => c + 1);
}
@janhesters
janhesters / home-page-container.test.js
Created September 26, 2020 12:39
Home page container tests.
import { fireEvent, render } from '@testing-library/react';
import { describe } from 'riteway';
import HomePage from './home-page-container.js';
describe('HomePage container', async assert => {
const { getByText, getByTestId } = render(<HomePage />);
fireEvent.click(getByText(/increment/i));