Skip to content

Commit 47f3008

Browse files
committed
chore: adding and configuring jest file
1 parent ed7a095 commit 47f3008

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ const styles = StyleSheet.create({
112112

113113
To become more familiar with the usage of the library, check out the [example project](./example/).
114114

115+
## Testing
116+
117+
To mock the package's methods and components using the default mock configuration provided, follow these steps:
118+
119+
- Create a file named `@mhpdev/react-native-speech.ts` inside your `__mocks__` directory.
120+
121+
- Copy the following code into that file:
122+
123+
```ts
124+
export * from '@mhpdev/react-native-speech/jest';
125+
```
126+
115127
## Contributing
116128

117129
See the [contributing guide](./docs/CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

jest/index.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {createElement} from 'react';
2+
import type {
3+
VoiceProps,
4+
EventProps,
5+
VoiceOptions,
6+
ProgressEventProps,
7+
} from '../src/NativeSpeech';
8+
import type {
9+
HighlightedTextProps,
10+
HighlightedSegmentArgs,
11+
HighlightedSegmentProps,
12+
} from '../src/components/types';
13+
14+
class SpeechMock {
15+
static reset = jest.fn<void, []>();
16+
static stop = jest.fn<Promise<void>, []>();
17+
static pause = jest.fn<Promise<boolean>, []>();
18+
static resume = jest.fn<Promise<boolean>, []>();
19+
static speak = jest.fn<Promise<void>, [string]>();
20+
static isSpeaking = jest.fn<Promise<boolean>, []>();
21+
static initialize = jest.fn<void, [VoiceOptions]>();
22+
static getAvailableVoices = jest.fn<Promise<VoiceProps[]>, [string?]>();
23+
static speakWithOptions = jest.fn<Promise<void>, [string, VoiceOptions]>();
24+
static onError = jest.fn();
25+
static onStart = jest.fn();
26+
static onFinish = jest.fn();
27+
static onPause = jest.fn();
28+
static onResume = jest.fn();
29+
static onStopped = jest.fn();
30+
static onProgress = jest.fn();
31+
}
32+
33+
export const HighlightedText: React.FC<HighlightedTextProps> = props => {
34+
return createElement('HighlightedText', props, props.text);
35+
};
36+
37+
export default SpeechMock;
38+
export type {
39+
VoiceProps,
40+
EventProps,
41+
VoiceOptions,
42+
ProgressEventProps,
43+
HighlightedTextProps,
44+
HighlightedSegmentArgs,
45+
HighlightedSegmentProps,
46+
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"files": [
1010
"src",
1111
"lib",
12+
"jest",
1213
"android",
1314
"ios",
1415
"cpp",

0 commit comments

Comments
 (0)