Skip to content

Commit 5925abe

Browse files
fix: Address lint and typecheck issues in ScrollTimeline and ViewTimeline implementation
- Fix currentTime return type in MockedAnimationTimeline to allow number | null - Remove unused parameters and fix any types in test files - Add disconnect() method to ViewTimeline interface - Remove unused #cleanup method from ViewTimeline - Fix lint issues with proper type assertions Co-authored-by: Ivan Galiatin <[email protected]>
1 parent d9ea3c1 commit 5925abe

File tree

7 files changed

+14
-17
lines changed

7 files changed

+14
-17
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mocks/web-animations-api/AnimationTimeline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class MockedAnimationTimeline implements AnimationTimeline {
55
}
66
}
77

8-
get currentTime() {
8+
get currentTime(): number | null {
99
return performance.now();
1010
}
1111
}

src/mocks/web-animations-api/ScrollTimeline.env.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('ScrollTimeline Environment Tests', () => {
88
afterEach(() => {
99
// Clean up global modifications
1010
if ('ScrollTimeline' in window) {
11-
delete (window as any).ScrollTimeline;
11+
delete (window as Record<string, unknown>).ScrollTimeline;
1212
}
1313
});
1414

@@ -48,7 +48,7 @@ describe('ScrollTimeline Environment Tests', () => {
4848
it('should work in different test environments', () => {
4949
expect(() => {
5050
const timeline = new ScrollTimeline();
51-
timeline.currentTime; // Should not throw
51+
expect(timeline.currentTime).toBeDefined(); // Should not throw
5252
}).not.toThrow();
5353
});
5454

src/mocks/web-animations-api/ScrollTimeline.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('ScrollTimeline', () => {
88
afterEach(() => {
99
// Clean up any global modifications
1010
if ('ScrollTimeline' in window) {
11-
delete (window as any).ScrollTimeline;
11+
delete (window as Record<string, unknown>).ScrollTimeline;
1212
}
1313
});
1414

@@ -28,7 +28,7 @@ describe('ScrollTimeline', () => {
2828
it('should throw error for invalid axis parameter', () => {
2929
expect(() => {
3030
new ScrollTimeline({
31-
axis: 'invalid' as any
31+
axis: 'invalid' as 'block' | 'inline' | 'x' | 'y'
3232
});
3333
}).toThrow('Invalid axis value: invalid');
3434
});

src/mocks/web-animations-api/ViewTimeline.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { MockedViewTimeline, mockViewTimeline } from './ViewTimeline';
22

33
// Mock IntersectionObserver for testing
4-
const mockIntersectionObserver = jest.fn().mockImplementation((callback, options) => ({
4+
const mockIntersectionObserver = jest.fn().mockImplementation(() => ({
55
observe: jest.fn(),
66
disconnect: jest.fn(),
77
unobserve: jest.fn()
@@ -23,7 +23,7 @@ describe('ViewTimeline', () => {
2323

2424
// Clean up any global modifications
2525
if ('ViewTimeline' in window) {
26-
delete (window as any).ViewTimeline;
26+
delete (window as Record<string, unknown>).ViewTimeline;
2727
}
2828

2929
jest.clearAllMocks();
@@ -45,13 +45,13 @@ describe('ViewTimeline', () => {
4545

4646
it('should throw error when subject is missing', () => {
4747
expect(() => {
48-
new ViewTimeline({} as any);
48+
new ViewTimeline({} as Parameters<ViewTimelineConstructor>[0]);
4949
}).toThrow('ViewTimeline requires a valid Element as subject');
5050
});
5151

5252
it('should throw error when subject is not an Element', () => {
5353
expect(() => {
54-
new ViewTimeline({ subject: 'not an element' as any });
54+
new ViewTimeline({ subject: 'not an element' as unknown as Element });
5555
}).toThrow('ViewTimeline requires a valid Element as subject');
5656
});
5757

@@ -60,7 +60,7 @@ describe('ViewTimeline', () => {
6060
expect(() => {
6161
new ViewTimeline({
6262
subject: mockElement,
63-
axis: 'invalid' as any
63+
axis: 'invalid' as 'block' | 'inline' | 'x' | 'y'
6464
});
6565
}).toThrow('Invalid axis value: invalid');
6666
});
@@ -131,7 +131,7 @@ describe('ViewTimeline', () => {
131131

132132
it('should work when IntersectionObserver is not available', () => {
133133
// Remove IntersectionObserver
134-
delete (global as any).IntersectionObserver;
134+
delete (global as Record<string, unknown>).IntersectionObserver;
135135

136136
const mockElement = document.createElement('div');
137137
const timeline = new ViewTimeline({ subject: mockElement });

src/mocks/web-animations-api/ViewTimeline.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@ class MockedViewTimeline
9797
this.#observer = null;
9898
}
9999
}
100-
101-
#cleanup() {
102-
this.disconnect();
103-
}
104100
}
105101

106102
function mockViewTimeline() {

src/mocks/web-animations-api/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ declare global {
1717
interface ViewTimeline extends AnimationTimeline {
1818
readonly subject: Element;
1919
readonly axis: 'block' | 'inline' | 'x' | 'y';
20+
disconnect(): void;
2021
}
2122

2223
interface ViewTimelineConstructor {

0 commit comments

Comments
 (0)