marko-js / testing-library

Simple and complete Marko testing utilities that encourage good testing practices.
MIT License
32 stars 2 forks source link

feat: expose helper to perform action and wait for update #13

Closed DylanPiercey closed 3 years ago

DylanPiercey commented 3 years ago

Description

This PR exposes a helper called act which allows for an easy way to perform any mutation and wait for Marko components to update. It works similarly to await fireEvent helpers and the core implementation has been refactored for all of those helpers to use this underlying helper.

Motivation and Context

This makes it easy to do something like:

import { render, act } from "@marko/testing-library";

const { getByText } = await render(template);

await act(() => getByText("My Button").click());

or

import userEvent from "@testing-library/user-event";
import { render, act } from "@marko/testing-library";

const { getByDisplayValue } = await render(template);

await act(() => userEvent.type(getByDisplayValue("Hello"), " World"));

Checklist:

codecov[bot] commented 3 years ago

Codecov Report

Merging #13 (4542a11) into main (e906526) will decrease coverage by 0.09%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #13      +/-   ##
==========================================
- Coverage   96.17%   96.07%   -0.10%     
==========================================
  Files           3        3              
  Lines         157      153       -4     
  Branches       39       37       -2     
==========================================
- Hits          151      147       -4     
  Misses          6        6              
Impacted Files Coverage Δ
src/index-browser.ts 95.94% <100.00%> (ø)
src/index.ts 97.77% <100.00%> (ø)
src/shared.ts 94.11% <100.00%> (-0.62%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e906526...4542a11. Read the comment docs.