#unit testing with Karma and Jasmine in my backend service
1 messages · Page 1 of 1 (latest)
umm, I have a backend API that checks the availability of a username.
I have an AccountService in angular that implements that so the method name is called checkUsernameAvailability(username: string){}
now in my Unit Test I am trying to subscribe in this method but it never returns the 204 OK RESULT it doesn't also return a 409 Conflict result.
code:
let component: TestComponent; let fixture: ComponentFixture<TestComponent>; let service: AccountService; beforeEach(async () ~~=~~> { await TestBed.configureTestingModule({ declarations: [ TestComponent ], declarations:[AccountService] }) .compileComponents(); service = TestBed.Inject(AccountService); }); beforeEach(() => { fixture = TestBed.createComponent(TestComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should return 200', () => { service.checkUsernameAvailability('test').subscribe(response => {console.info(response)}) }); });```
what i really want to do is get the actual response from the API. I'm trying to that by subscribing but when Im checking the console.info response. it doesn't show any JSON responses
That isn't enough code. and you shouldn't be testing a service in a component test.
What you're tryng to do, using a frontend component unit test, is to test your backend REST service. That isn't the right place to do that. Test your backend using backend tests.