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,
@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:
@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));
@janhesters
janhesters / home-page-component.js
Created September 26, 2020 12:35
Home page component.
import React from 'react';
const HomePage = ({ count, onIncrementClick = () => {} }) => (
<main>
<p className="count" data-testid="count">
{count}
</p>
<button className="increment-button" onClick={onIncrementClick}>
Increment
</button>
@janhesters
janhesters / home-page-component.test.js
Created September 26, 2020 12:34
Tests for home page component.
import React from 'react';
import { describe } from 'riteway';
import render from 'riteway/render-component.js';
import HomePage from './home-page-component.js';
const createProps = ({ count = 0 } = {}) => ({ count });
describe('HomePage component', async assert => {
const createHomePage = (props = {}) => render(<HomePage {...props} />);
@janhesters
janhesters / home-page-component.js
Created September 26, 2020 12:33
Home page component skeleton.
import React, { Fragment } from 'react';
function HomePage() {
return <Fragment></Fragment>
}
export default HomePage;