Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { describe, expect, test } from 'tstyche';

import {
advanceAnimationByFrame,
advanceAnimationByTime,
getAnimatedStyle,
setUpTests,
withReanimatedTimer,
} from '..';

// Regression coverage for
// https://github.com/software-mansion/react-native-reanimated/issues/11082.
//
// TypeScript consumers don't read `jestUtils/index.native.ts`, so the types
// of `jestUtils/index.ts` (the web stub) have to match it. The web pass of
// `scripts/test-ts.sh` resolves this file without the `.native` suffix.

describe('getAnimatedStyle', () => {
test('takes a component and returns its style', () => {
expect(getAnimatedStyle).type.toBeCallableWith({ props: {} });
expect(getAnimatedStyle).type.not.toBeCallableWith();
expect(getAnimatedStyle({ props: {} })).type.toHaveProperty('opacity');
});
});

describe('setUpTests', () => {
test('accepts an optional framerate config', () => {
expect(setUpTests).type.toBeCallableWith();
expect(setUpTests).type.toBeCallableWith({ fps: 30 });
});
});

describe('withReanimatedTimer', () => {
test('requires the test callback', () => {
expect(withReanimatedTimer).type.toBeCallableWith(() => undefined);
expect(withReanimatedTimer).type.not.toBeCallableWith();
});
});

describe('advanceAnimationByTime', () => {
test('accepts an optional time', () => {
expect(advanceAnimationByTime).type.toBeCallableWith();
expect(advanceAnimationByTime).type.toBeCallableWith(100);
});
});

describe('advanceAnimationByFrame', () => {
test('requires the frame count', () => {
expect(advanceAnimationByFrame).type.toBeCallableWith(3);
expect(advanceAnimationByFrame).type.not.toBeCallableWith();
});
});

describe('jest matchers', () => {
test('declares `toHaveAnimatedStyle`', () => {
expect<jest.Matchers<void>['toHaveAnimatedStyle']>().type.toBeCallableWith(
{ opacity: 1 },
{ shouldMatchAllProps: true }
);
});

test('declares `toHaveAnimatedProps`', () => {
expect<jest.Matchers<void>['toHaveAnimatedProps']>().type.toBeCallableWith({
text: 'text',
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the Jest utilities, such as `getAnimatedStyle`, and the `toHaveAnimatedStyle` and `toHaveAnimatedProps` matchers having the types of the web stub, or none, for TypeScript consumers.
32 changes: 20 additions & 12 deletions packages/react-native-reanimated/src/jestUtils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@
* Stubbed for web, where we don't use this file;
*/

export function withReanimatedTimer() {
// NOOP
}
// Consumers' TypeScript doesn't read `index.native.ts`, so the stub borrows its
// signatures (and, through the import, the `jest.Matchers` augmentation) to keep
// the published types the same as what Jest runs.
import type * as JestUtils from './index.native';

export function advanceAnimationByTime() {
export const withReanimatedTimer: typeof JestUtils.withReanimatedTimer = () => {
// NOOP
}
};

export function advanceAnimationByFrame() {
// NOOP
}
export const advanceAnimationByTime: typeof JestUtils.advanceAnimationByTime =
() => {
// NOOP
};

export const advanceAnimationByFrame: typeof JestUtils.advanceAnimationByFrame =
() => {
// NOOP
};

export function setUpTests() {
export const setUpTests: typeof JestUtils.setUpTests = () => {
// NOOP
}
};

export function getAnimatedStyle() {
export const getAnimatedStyle: typeof JestUtils.getAnimatedStyle = () => {
// NOOP
}
return undefined as never;
};

export { cloneWorklet, worklet } from './common';
Loading