1
1
import { render , screen } from "@testing-library/react" ;
2
2
import * as React from "react" ;
3
3
4
- import { testDependencies } from "../../../../../testing/test-dependencies" ;
4
+ import { testDependenciesV2 } from "../../../../../testing/test-dependencies" ;
5
5
import * as Dependencies from "../../dependencies" ;
6
6
7
7
import VideoTranscriptLink from "./video-transcript-link" ;
8
8
9
9
describe ( "VideoTranscriptLink" , ( ) => {
10
10
beforeEach ( ( ) => {
11
- jest . spyOn ( Dependencies , "getDependencies " ) . mockReturnValue ( {
12
- ...testDependencies ,
11
+ jest . spyOn ( Dependencies , "useDependencies " ) . mockReturnValue ( {
12
+ ...testDependenciesV2 ,
13
13
useVideo : ( videoId , kind ) => {
14
14
if ( videoId === "5qap5aO4i9A" ) {
15
15
return {
@@ -135,11 +135,15 @@ describe("VideoTranscriptLink", () => {
135
135
136
136
it ( "should link to /transcript/videoNotFound if the URL is not a youtube URL" , ( ) => {
137
137
// Arrange
138
- jest . spyOn ( Dependencies , "getDependencies" ) . mockReturnValue ( {
139
- ...testDependencies ,
140
- // @ts -expect-error - TS2322 - Type '(videoId: string, kind: VideoKind) => { status: "success"; data: {}; }' is not assignable to type '(id: string, kind: VideoKind) => Result<{ video: VideoData | null | undefined; }>'.
138
+ jest . spyOn ( Dependencies , "useDependencies" ) . mockReturnValue ( {
139
+ ...testDependenciesV2 ,
141
140
useVideo : ( videoId , kind ) => {
142
- return { status : "success" , data : { } } ;
141
+ return {
142
+ status : "success" ,
143
+ data : {
144
+ video : null ,
145
+ } ,
146
+ } ;
143
147
} ,
144
148
} ) ;
145
149
@@ -152,8 +156,8 @@ describe("VideoTranscriptLink", () => {
152
156
153
157
it ( "should handle a success state" , ( ) => {
154
158
// Arrange
155
- jest . spyOn ( Dependencies , "getDependencies " ) . mockReturnValue ( {
156
- ...testDependencies ,
159
+ jest . spyOn ( Dependencies , "useDependencies " ) . mockReturnValue ( {
160
+ ...testDependenciesV2 ,
157
161
useVideo : ( videoId , kind ) => {
158
162
return { status : "loading" } ;
159
163
} ,
@@ -166,11 +170,15 @@ describe("VideoTranscriptLink", () => {
166
170
167
171
it ( "should link to /transcript/videoNotFound if there's no data" , ( ) => {
168
172
// Arrange
169
- jest . spyOn ( Dependencies , "getDependencies" ) . mockReturnValue ( {
170
- ...testDependencies ,
171
- // @ts -expect-error - TS2322 - Type '(videoId: string, kind: VideoKind) => { status: "success"; data: {}; }' is not assignable to type '(id: string, kind: VideoKind) => Result<{ video: VideoData | null | undefined; }>'.
173
+ jest . spyOn ( Dependencies , "useDependencies" ) . mockReturnValue ( {
174
+ ...testDependenciesV2 ,
172
175
useVideo : ( videoId , kind ) => {
173
- return { status : "success" , data : { } } ;
176
+ return {
177
+ status : "success" ,
178
+ data : {
179
+ video : null ,
180
+ } ,
181
+ } ;
174
182
} ,
175
183
} ) ;
176
184
@@ -183,11 +191,10 @@ describe("VideoTranscriptLink", () => {
183
191
184
192
it ( "should handle an error state" , ( ) => {
185
193
// Arrange
186
- jest . spyOn ( Dependencies , "getDependencies" ) . mockReturnValue ( {
187
- ...testDependencies ,
188
- // @ts -expect-error - TS2322 - Type '(videoId: string, kind: VideoKind) => { status: "error"; }' is not assignable to type '(id: string, kind: VideoKind) => Result<{ video: VideoData | null | undefined; }>'.
194
+ jest . spyOn ( Dependencies , "useDependencies" ) . mockReturnValue ( {
195
+ ...testDependenciesV2 ,
189
196
useVideo : ( videoId , kind ) => {
190
- return { status : "error" } ;
197
+ return { status : "error" , error : new Error ( ) } ;
191
198
} ,
192
199
} ) ;
193
200
@@ -198,8 +205,8 @@ describe("VideoTranscriptLink", () => {
198
205
199
206
it ( "should handle an aborted state" , ( ) => {
200
207
// Arrange
201
- jest . spyOn ( Dependencies , "getDependencies " ) . mockReturnValue ( {
202
- ...testDependencies ,
208
+ jest . spyOn ( Dependencies , "useDependencies " ) . mockReturnValue ( {
209
+ ...testDependenciesV2 ,
203
210
useVideo : ( videoId , kind ) => {
204
211
return { status : "aborted" } ;
205
212
} ,
0 commit comments