#unit testing with Karma and Jasmine in my backend service

1 messages · Page 1 of 1 (latest)

trail echo
#

I'm not sure what you want to do exactly, and you haven't posted any code, so...
Post the code of what you want to test. Tell what this code is supposed to do. Then post the code you tried to write to test it, and tell precisely what problem you faced.

snow thicket
#

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

rain obsidian
#

That isn't enough code. and you shouldn't be testing a service in a component test.

trail echo
#

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.