Skip to content

Commit d282d14

Browse files
committed
32 problems left
1 parent 4746b3b commit d282d14

File tree

5 files changed

+41
-38
lines changed

5 files changed

+41
-38
lines changed

src/__tests__/__snapshots__/render-debug.test.tsx.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ exports[`debug with only props from TextInput components 1`] = `
288288
exports[`debug: another custom message 1`] = `
289289
"another custom message
290290
291+
291292
<View>
292293
<Text>
293294
Is the banana fresh?
@@ -370,6 +371,7 @@ exports[`debug: another custom message 1`] = `
370371
exports[`debug: with message 1`] = `
371372
"my custom message
372373
374+
373375
<View>
374376
<Text>
375377
Is the banana fresh?

src/__tests__/render-debug.test.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ test('debug', () => {
9898
screen.debug({ message: 'another custom message' });
9999

100100
const mockCalls = jest.mocked(logger.info).mock.calls;
101-
expect(stripAnsi(mockCalls[0][0])).toMatchSnapshot();
102-
expect(stripAnsi(mockCalls[1][0] + mockCalls[1][1])).toMatchSnapshot('with message');
103-
expect(stripAnsi(mockCalls[2][0] + mockCalls[2][1])).toMatchSnapshot('another custom message');
101+
expect(mockCalls[0][0]).toMatchSnapshot();
102+
expect(`${mockCalls[1][0]}\n${mockCalls[1][1]}`).toMatchSnapshot('with message');
103+
expect(`${mockCalls[2][0]}\n${mockCalls[2][1]}`).toMatchSnapshot('another custom message');
104104

105105
const mockWarnCalls = jest.mocked(logger.warn).mock.calls;
106106
expect(mockWarnCalls[0]).toMatchInlineSnapshot(`
@@ -117,17 +117,15 @@ test('debug changing component', () => {
117117
screen.debug();
118118

119119
const mockCalls = jest.mocked(logger.info).mock.calls;
120-
expect(stripAnsi(mockCalls[0][0])).toMatchSnapshot(
121-
'bananaFresh button message should now be "fresh"',
122-
);
120+
expect(mockCalls[0][0]).toMatchSnapshot('bananaFresh button message should now be "fresh"');
123121
});
124122

125123
test('debug with only children prop', () => {
126124
render(<Banana />);
127125
screen.debug({ mapProps: () => ({}) });
128126

129127
const mockCalls = jest.mocked(logger.info).mock.calls;
130-
expect(stripAnsi(mockCalls[0][0])).toMatchSnapshot();
128+
expect(mockCalls[0][0]).toMatchSnapshot();
131129
});
132130

133131
test('debug with only prop whose value is bananaChef', () => {
@@ -145,7 +143,7 @@ test('debug with only prop whose value is bananaChef', () => {
145143
});
146144

147145
const mockCalls = jest.mocked(logger.info).mock.calls;
148-
expect(stripAnsi(mockCalls[0][0])).toMatchSnapshot();
146+
expect(mockCalls[0][0]).toMatchSnapshot();
149147
});
150148

151149
test('debug with only props from TextInput components', () => {
@@ -155,7 +153,7 @@ test('debug with only props from TextInput components', () => {
155153
});
156154

157155
const mockCalls = jest.mocked(logger.info).mock.calls;
158-
expect(stripAnsi(mockCalls[0][0])).toMatchSnapshot();
156+
expect(mockCalls[0][0]).toMatchSnapshot();
159157
});
160158

161159
test('debug should use debugOptions from config when no option is specified', () => {
@@ -169,7 +167,7 @@ test('debug should use debugOptions from config when no option is specified', ()
169167
screen.debug();
170168

171169
const mockCalls = jest.mocked(logger.info).mock.calls;
172-
expect(stripAnsi(mockCalls[0][0])).toMatchSnapshot();
170+
expect(mockCalls[0][0]).toMatchSnapshot();
173171
});
174172

175173
test('filtering out props through mapProps option should not modify component', () => {
@@ -190,5 +188,5 @@ test('debug should use given options over config debugOptions', () => {
190188
screen.debug({ mapProps: (props) => props });
191189

192190
const mockCalls = jest.mocked(logger.info).mock.calls;
193-
expect(stripAnsi(mockCalls[0][0])).toMatchSnapshot();
191+
expect(mockCalls[0][0]).toMatchSnapshot();
194192
});

src/helpers/logger.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ import chalk from 'chalk';
44
import redent from 'redent';
55

66
export const logger = {
7-
debug(message: any, ...args: any[]) {
7+
debug(message: unknown, ...args: unknown[]) {
88
const output = formatMessage('●', message, ...args);
99
nodeConsole.debug(chalk.dim(output));
1010
},
1111

12-
info(message: any, ...args: any[]) {
12+
info(message: unknown, ...args: unknown[]) {
1313
const output = formatMessage('●', message, ...args);
1414
nodeConsole.info(output);
1515
},
1616

17-
warn(message: any, ...args: any[]) {
17+
warn(message: unknown, ...args: unknown[]) {
1818
const output = formatMessage('▲', message, ...args);
1919
nodeConsole.warn(chalk.yellow(output));
2020
},
2121

22-
error(message: any, ...args: any[]) {
22+
error(message: unknown, ...args: unknown[]) {
2323
const output = formatMessage('■', message, ...args);
2424
nodeConsole.error(chalk.red(output));
2525
},
2626
};
2727

28-
function formatMessage(symbol: string, message: any, ...args: any[]) {
28+
function formatMessage(symbol: string, message: unknown, ...args: unknown[]) {
2929
const formatted = nodeUtil.format(message, ...args);
3030
const indented = redent(formatted, 4);
3131
return ` ${symbol} ${indented.trimStart()}\n`;

src/queries/unsafe-props.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import prettyFormat from 'pretty-format';
33
import { ErrorWithStack, prepareErrorMessage } from '../helpers/errors';
44
import { createQueryByError } from '../helpers/errors';
55

6+
export type UnsafeProps = Record<string, unknown>;
7+
68
const UNSAFE_getByProps = (
79
instance: ReactTestInstance,
8-
): ((props: { [propName: string]: any }) => ReactTestInstance) =>
9-
function getByPropsFn(props: { [propName: string]: any }) {
10+
): ((props: UnsafeProps) => ReactTestInstance) =>
11+
function getByPropsFn(props: UnsafeProps) {
1012
try {
1113
return instance.findByProps(props);
1214
} catch (error) {
@@ -16,8 +18,8 @@ const UNSAFE_getByProps = (
1618

1719
const UNSAFE_getAllByProps = (
1820
instance: ReactTestInstance,
19-
): ((props: { [propName: string]: any }) => Array<ReactTestInstance>) =>
20-
function getAllByPropsFn(props: { [propName: string]: any }) {
21+
): ((props: UnsafeProps) => Array<ReactTestInstance>) =>
22+
function getAllByPropsFn(props: UnsafeProps) {
2123
const results = instance.findAllByProps(props);
2224
if (results.length === 0) {
2325
throw new ErrorWithStack(
@@ -30,8 +32,8 @@ const UNSAFE_getAllByProps = (
3032

3133
const UNSAFE_queryByProps = (
3234
instance: ReactTestInstance,
33-
): ((props: { [propName: string]: any }) => ReactTestInstance | null) =>
34-
function queryByPropsFn(props: { [propName: string]: any }) {
35+
): ((props: UnsafeProps) => ReactTestInstance | null) =>
36+
function queryByPropsFn(props: UnsafeProps) {
3537
try {
3638
return UNSAFE_getByProps(instance)(props);
3739
} catch (error) {
@@ -40,10 +42,8 @@ const UNSAFE_queryByProps = (
4042
};
4143

4244
const UNSAFE_queryAllByProps =
43-
(
44-
instance: ReactTestInstance,
45-
): ((props: { [propName: string]: any }) => Array<ReactTestInstance>) =>
46-
(props: { [propName: string]: any }) => {
45+
(instance: ReactTestInstance): ((props: UnsafeProps) => Array<ReactTestInstance>) =>
46+
(props: UnsafeProps) => {
4747
try {
4848
return UNSAFE_getAllByProps(instance)(props);
4949
} catch {
@@ -53,10 +53,10 @@ const UNSAFE_queryAllByProps =
5353

5454
// Unsafe aliases
5555
export type UnsafeByPropsQueries = {
56-
UNSAFE_getByProps: (props: { [key: string]: any }) => ReactTestInstance;
57-
UNSAFE_getAllByProps: (props: { [key: string]: any }) => Array<ReactTestInstance>;
58-
UNSAFE_queryByProps: (props: { [key: string]: any }) => ReactTestInstance | null;
59-
UNSAFE_queryAllByProps: (props: { [key: string]: any }) => Array<ReactTestInstance>;
56+
UNSAFE_getByProps: (props: UnsafeProps) => ReactTestInstance;
57+
UNSAFE_getAllByProps: (props: UnsafeProps) => Array<ReactTestInstance>;
58+
UNSAFE_queryByProps: (props: UnsafeProps) => ReactTestInstance | null;
59+
UNSAFE_queryAllByProps: (props: UnsafeProps) => Array<ReactTestInstance>;
6060
};
6161

6262
// TODO: migrate to makeQueries pattern

src/queries/unsafe-type.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import * as React from 'react';
33
import { ErrorWithStack, prepareErrorMessage } from '../helpers/errors';
44
import { createQueryByError } from '../helpers/errors';
55

6+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7+
export type UnsafeComponentType = React.ComponentType<any>;
8+
69
const UNSAFE_getByType = (
710
instance: ReactTestInstance,
8-
): ((type: React.ComponentType<any>) => ReactTestInstance) =>
9-
function getByTypeFn(type: React.ComponentType<any>) {
11+
): ((type: UnsafeComponentType) => ReactTestInstance) =>
12+
function getByTypeFn(type: UnsafeComponentType) {
1013
try {
1114
return instance.findByType(type);
1215
} catch (error) {
@@ -16,8 +19,8 @@ const UNSAFE_getByType = (
1619

1720
const UNSAFE_getAllByType = (
1821
instance: ReactTestInstance,
19-
): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) =>
20-
function getAllByTypeFn(type: React.ComponentType<any>) {
22+
): ((type: UnsafeComponentType) => Array<ReactTestInstance>) =>
23+
function getAllByTypeFn(type: UnsafeComponentType) {
2124
const results = instance.findAllByType(type);
2225
if (results.length === 0) {
2326
throw new ErrorWithStack('No instances found', getAllByTypeFn);
@@ -27,8 +30,8 @@ const UNSAFE_getAllByType = (
2730

2831
const UNSAFE_queryByType = (
2932
instance: ReactTestInstance,
30-
): ((type: React.ComponentType<any>) => ReactTestInstance | null) =>
31-
function queryByTypeFn(type: React.ComponentType<any>) {
33+
): ((type: UnsafeComponentType) => ReactTestInstance | null) =>
34+
function queryByTypeFn(type: UnsafeComponentType) {
3235
try {
3336
return UNSAFE_getByType(instance)(type);
3437
} catch (error) {
@@ -37,8 +40,8 @@ const UNSAFE_queryByType = (
3740
};
3841

3942
const UNSAFE_queryAllByType =
40-
(instance: ReactTestInstance): ((type: React.ComponentType<any>) => Array<ReactTestInstance>) =>
41-
(type: React.ComponentType<any>) => {
43+
(instance: ReactTestInstance): ((type: UnsafeComponentType) => Array<ReactTestInstance>) =>
44+
(type: UnsafeComponentType) => {
4245
try {
4346
return UNSAFE_getAllByType(instance)(type);
4447
} catch {

0 commit comments

Comments
 (0)