Utilities for testing Ink apps
Install
$ npm install --save-dev ink-testing-library
Usage
import React from 'react';import Text from 'ink';import render from 'ink-testing-library'; const Counter = count <Text>Count: count</Text>; const lastFrame rerender = ; === 'Count: 0'; //=> true ; === 'Count: 1'; //=> true
API
render(tree)
tree
Type: ReactElement
React component to render.
;
This function returns an object, which contains the following methods and properties.
lastFrame()
Type: function
Shortcut to stdout.lastFrame
.
frames
Type: array
Shortcut to stdout.frames
.
rerender(tree)
Type: function
tree
Type: ReactElement
Rerender root component with different props or replace with another component.
const rerender = ;;
unmount()
Type: function
Unmount current component.
const unmount = ;;
stdin
Type: object
write()
Type: function
Write data to current component's stdin stream.
import useInput Text from 'ink'; const Test = ; return …;; const stdin = ;stdin;
stdout
Type: object
lastFrame()
Type: function
Return the last rendered frame (output) from stdout stream.
const Test = <Text>Hello</Text>; const stdout = ;stdout; //=> 'Hello'
frames
Type: array
Array of all rendered frames, where the last frame is also the last item in that array.
const Counter = count <Text>Count: count</Text>; const stdout rerender = ;; console; //=> ['Count: 0', 'Count: 1']
stderr
Type: object
lastFrame()
Type: function
Same as lastFrame
in stdout
, but for stderr stream.
frames
Type: array