Skip to content

Commit 62eba6a

Browse files
committed
fix: the jest file issue and its usage
1 parent 0230cc2 commit 62eba6a

3 files changed

Lines changed: 42 additions & 48 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ To mock the package's methods and components using the default mock configuratio
120120

121121
- Copy the following code into that file:
122122

123-
```ts
124-
export * from '@mhpdev/react-native-speech/jest';
123+
```js
124+
module.exports = require('@mhpdev/react-native-speech/jest');
125125
```
126126

127127
## Contributing

jest/index.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const mockFn = (...args) => {
2+
return undefined;
3+
};
4+
5+
const mockPromise = (...args) => Promise.resolve(undefined);
6+
const mockPromiseBool = (...args) => Promise.resolve(false);
7+
const mockPromiseArr = (...args) => Promise.resolve([]);
8+
9+
const {fn: jestFn} = require('jest-mock');
10+
const eventSub = {remove: jestFn()};
11+
const eventMock = jestFn(() => eventSub);
12+
13+
class Speech {
14+
static reset = mockFn;
15+
static stop = mockPromise;
16+
static initialize = mockFn;
17+
static speak = mockPromise;
18+
static pause = mockPromiseBool;
19+
static resume = mockPromiseBool;
20+
static isSpeaking = mockPromiseBool;
21+
static speakWithOptions = mockPromise;
22+
static getAvailableVoices = mockPromiseArr;
23+
static onError = eventMock;
24+
static onStart = eventMock;
25+
static onFinish = eventMock;
26+
static onPause = eventMock;
27+
static onResume = eventMock;
28+
static onStopped = eventMock;
29+
static onProgress = eventMock;
30+
}
31+
32+
const HighlightedText = jestFn(function HighlightedText() {
33+
return null;
34+
});
35+
36+
module.exports = {
37+
__esModule: true,
38+
default: Speech,
39+
HighlightedText,
40+
};

jest/index.ts

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)