Skip to content

Commit e51ba92

Browse files
committed
ci: run yarn install and adjust mocks
1 parent b41d510 commit e51ba92

2 files changed

Lines changed: 38 additions & 22 deletions

File tree

.github/workflows/publish.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ jobs:
2525
node-version: 18
2626
registry-url: https://npm.pkg.github.com/
2727
scope: '@omarsdev'
28+
cache: 'yarn'
2829

2930
- name: Install dependencies
30-
run: npm ci
31+
run: yarn install --frozen-lockfile
3132

3233
- name: Run tests
33-
run: npm test --if-present
34+
run: yarn test
3435

3536
- name: Configure git user
3637
run: |

__tests__/NativeContactsLastUpdated.test.ts

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ type RNTestGlobal = typeof globalThis & {
88
};
99
};
1010

11+
type TurboProxy = NonNullable<RNTestGlobal["__turboModuleProxy"]>;
12+
1113
const originalProxy = (globalThis as RNTestGlobal).__turboModuleProxy;
1214

1315
const createNativeMock = (): Spec => ({
@@ -20,24 +22,29 @@ afterEach(() => {
2022
(globalThis as RNTestGlobal).__turboModuleProxy = originalProxy;
2123
jest.resetModules();
2224
jest.resetAllMocks();
23-
jest.dontMock("react-native");
2425
});
2526

2627
describe("Native module resolution", () => {
2728
it("uses TurboModuleRegistry when the TurboModule proxy is present", () => {
2829
const fakeNative = createNativeMock();
29-
const getMock = jest.fn(() => fakeNative);
30+
const getMock = jest.fn(() => fakeNative) as unknown as TurboProxy["get"];
31+
32+
const getEnforcingMock = jest.fn() as unknown as TurboProxy["getEnforcing"];
3033

3134
(globalThis as RNTestGlobal).__turboModuleProxy = {
3235
get: getMock,
33-
getEnforcing: jest.fn(),
36+
getEnforcing: getEnforcingMock,
3437
};
3538

36-
jest.doMock("react-native", () => ({
37-
TurboModuleRegistry: { get: getMock, getEnforcing: jest.fn() },
38-
NativeModules: {},
39-
Platform: { select: jest.fn(() => undefined) },
40-
}));
39+
jest.doMock(
40+
"react-native",
41+
() => ({
42+
TurboModuleRegistry: { get: getMock, getEnforcing: getEnforcingMock },
43+
NativeModules: {},
44+
Platform: { select: jest.fn(() => undefined) },
45+
}),
46+
{ virtual: true }
47+
);
4148

4249
jest.isolateModules(() => {
4350
const Native = require("../src/specs/NativeContactsLastUpdated").default as Spec;
@@ -50,29 +57,37 @@ describe("Native module resolution", () => {
5057
delete (globalThis as RNTestGlobal).__turboModuleProxy;
5158

5259
const fakeNative = createNativeMock();
53-
const getMock = jest.fn(() => undefined);
60+
const getMock = jest.fn(() => undefined) as unknown as TurboProxy["get"];
5461

55-
jest.doMock("react-native", () => ({
56-
TurboModuleRegistry: { get: getMock, getEnforcing: jest.fn() },
57-
NativeModules: { ContactsLastUpdated: fakeNative },
58-
Platform: { select: jest.fn(() => undefined) },
59-
}));
62+
jest.doMock(
63+
"react-native",
64+
() => ({
65+
TurboModuleRegistry: { get: getMock, getEnforcing: jest.fn() },
66+
NativeModules: { ContactsLastUpdated: fakeNative },
67+
Platform: { select: jest.fn(() => undefined) },
68+
}),
69+
{ virtual: true }
70+
);
6071

6172
jest.isolateModules(() => {
6273
const Native = require("../src/specs/NativeContactsLastUpdated").default as Spec;
6374
expect(Native).toBe(fakeNative);
64-
expect(getMock).toHaveBeenCalledWith("ContactsLastUpdated");
75+
expect(getMock).not.toHaveBeenCalled();
6576
});
6677
});
6778

6879
it("throws a helpful error when the native module is unavailable", () => {
6980
delete (globalThis as RNTestGlobal).__turboModuleProxy;
7081

71-
jest.doMock("react-native", () => ({
72-
TurboModuleRegistry: { get: jest.fn(() => undefined), getEnforcing: jest.fn() },
73-
NativeModules: {},
74-
Platform: { select: jest.fn(() => undefined) },
75-
}));
82+
jest.doMock(
83+
"react-native",
84+
() => ({
85+
TurboModuleRegistry: { get: jest.fn(() => undefined), getEnforcing: jest.fn() },
86+
NativeModules: {},
87+
Platform: { select: jest.fn(() => undefined) },
88+
}),
89+
{ virtual: true }
90+
);
7691

7792
expect(() =>
7893
jest.isolateModules(() => {

0 commit comments

Comments
 (0)