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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function memoize(fn) { | |
const cache = new Map(); | |
return function(...args) { | |
const key = args.toString(); | |
if (cache.has(key)) { | |
return cache.get(key); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Pull Request | |
on: [pull_request] | |
jobs: | |
unit-and-integration: | |
strategy: | |
fail-fast: false | |
matrix: | |
command: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fn(implementation = () => {}) { | |
const mockFn = (...args) => { | |
mockFn.calls.push(args); | |
return implementation(...args); | |
}; | |
mockFn.calls = []; | |
return mockFn; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} />); |
NewerOlder