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
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
// 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, |
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
#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) |
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
// 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() { |
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)); |
NewerOlder