gpt4 book ai didi

angular - 错误 : StaticInjectorError(DynamicTestModule)[NotificationsComponent

转载 作者:行者123 更新时间:2023-11-28 20:02:42 26 4
gpt4 key购买 nike

运行 ng 测试 时完全错误:

Error: StaticInjectorError(DynamicTestModule)[NotificationsComponent

AuthService]:    StaticInjectorError(Platform: core)[NotificationsComponent AuthService]: 

 NullInjectorError: No provider for AuthService!

Expected undefined to be truthy.

Error: Expected undefined to be truthy.

    at stack (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:2176:17)

    at buildExpectationResult (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:2146:14)

    at Spec.expectationResultFactory (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:766:18)

    at Spec.addExpectationResult (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:444:34)

    at Expectation.addExpectationResult (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:710:21)

    at Expectation.toBeTruthy (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:2099:12)

    at Object. (http://localhost:9876/_karma_webpack_/webpack:/C:/../webTest/src/app/components/notifications/notifications.component.spec.ts:97:23)

    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/C:/C:/../webTest/node_modules/zone.js/dist/zone.js:388:1)

    at ProxyZoneSpec.webpackJsonp.../../../../zone.js/dist/proxy.js.ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/webpack:/C:/../webTest/node_modules/zone.js/dist/proxy.js:79:1)

    at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/webpack:/C:/../webTest/node_modules/zone.js/dist/zone.js:387:1)

我的代码服务:

describe('Component: Auth', () => {


    let component: AuthService;

    let fixture: ComponentFixture<AuthService>;


    beforeEach(() => {

        TestBed.configureTestingModule({

            declarations: [AuthService]

        })

        fixture = TestBed.createComponent(AuthService);

        component = fixture.componentInstance;

    });

});

你能问我,问题是什么吗?

最佳答案

像下面这样使用它:

服务应该在providers数组中。

describe('Component: Auth', () => {
let component: AuthService;
let fixture: ComponentFixture<AuthService>;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [],
providers: [AuthService] // **Like this.**
})
fixture = TestBed.createComponent(AuthService);
component = fixture.componentInstance;
});

});

关于angular - 错误 : StaticInjectorError(DynamicTestModule)[NotificationsComponent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50449449/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com