如果您使用的是ASP.NET Core SignalR,则可能需要在服务器端的Startup.cs文件中添加以下内容:
app.UseEndpoints(endpoints =>
{
endpoints.MapHub("/yourHubPath");
});
其中YourHubClass是您的Hub类,/yourHubPath是您的Hub路径。
如果您已经添加了这些内容,仍然收到“Not Found”错误,则可能是因为测试运行器无法识别SignalR Hub终结点。此时,您需要在测试文件的imports中添加以下内容:
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { signalRMockBuilder } from '../../testing/signalr-mock-builder';
然后使用以下方式注入signalRMockBuilder:
TestBed.configureTestingModule({
imports: [
HttpClientTestingModule,
signalRMockBuilder()
],
providers: [
YourService
]
}).compileComponents();
请注意,在上面的代码中,您需要将signalRMockBuilder的引入路径更改为适合您测试项目的路径。
这些步骤应该能够解决“Failed to complete negotiation with the server: Error: Not Found”错误。