CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
readme.md154 linesDownload Raw Back to ink-testing-library
1# ink-testing-library ![test](https://github.com/vadimdemedes/ink-testing-library/workflows/test/badge.svg)2 3> Utilities for testing [Ink](https://github.com/vadimdemedes/ink) apps4 5## Install6 7```8$ npm install --save-dev ink-testing-library9```10 11## Usage12 13```jsx14import React from 'react';15import {Text} from 'ink';16import {render} from 'ink-testing-library';17 18const Counter = ({count}) => <Text>Count: {count}</Text>;19 20const {lastFrame, rerender} = render(<Counter count={0}/>);21lastFrame() === 'Count: 0'; //=> true22 23rerender(<Counter count={1}/>);24lastFrame() === 'Count: 1'; //=> true25```26 27## API28 29### render(tree)30 31#### tree32 33Type: `ReactElement`34 35React component to render.36 37```jsx38render(<MyApp/>);39```40 41This function returns an object, which contains the following methods and properties.42 43#### lastFrame()44 45Type: `function`46 47Shortcut to [`stdout.lastFrame`](#lastframe-1).48 49#### frames50 51Type: `array`52 53Shortcut to [`stdout.frames`](#frames-1).54 55#### rerender(tree)56 57Type: `function`58 59##### tree60 61Type: `ReactElement`62 63Rerender root component with different props or replace with another component.64 65```jsx66const {rerender} = render(<OldApp/>);67rerender(<NewApp/>);68```69 70#### unmount()71 72Type: `function`73 74Unmount current component.75 76```jsx77const {unmount} = render(<Test/>);78unmount();79```80 81#### stdin82 83Type: `object`84 85##### write()86 87Type: `function`88 89Write data to current component's stdin stream.90 91```jsx92import {useInput, Text} from 'ink';93 94const Test = () => {95	useInput(input => {96		console.log(input);97		//=> 'hello'98	});99 100	return …;101};102 103const {stdin} = render(<Test/>);104stdin.write('hello');105```106 107#### stdout108 109Type: `object`110 111##### lastFrame()112 113Type: `function`114 115Return the last rendered frame (output) from stdout stream.116 117```jsx118const Test = () => <Text>Hello</Text>;119 120const {stdout} = render(<Test/>);121stdout.lastFrame(); //=> 'Hello'122```123 124##### frames125 126Type: `array`127 128Array of all rendered frames, where the last frame is also the last item in that array.129 130```jsx131const Counter = ({count}) => <Text>Count: {count}</Text>;132 133const {stdout, rerender} = render(<Counter count={0}/>);134rerender(<Counter count={1}/>);135 136console.log(stdout.frames); //=> ['Count: 0', 'Count: 1']137```138 139#### stderr140 141Type: `object`142 143##### lastFrame()144 145Type: `function`146 147Same as [`lastFrame`](#lastframe-1) in [`stdout`](#stdout), but for stderr stream.148 149##### frames150 151Type: `array`152 153Same as [`frames`](#frames-1) in [`stdout`](#stdout), but for stderr stream.154 
basant307/AI_Governance_Project · CoolFace