i am struggling to have an issue with injecting DOCUMENT in my test service
i have a service like this
export class ClientValueExtractorService {
constructor(
@Inject(DOCUMENT) private _document: Document,
) {}
public getValues() {
return this._document.cookie.split('; ') // some cookie processing here
}
now trying to write a test to set a cookie and make an assertion by calling getValues (this actually work before use token value as document in provide section, changed to DI document token then have an issue)
here it is test that i am trying
beforeEach(
() => {
mockDocument = {
cookie: '',
} as Document;
TestBed.configureTestingModule({
providers: [
{ provide: VerificationService, useValue: jest.fn().mockImplementation(() => ({
getVerificationId: jest.fn(() => verificationId),
}))() },
ClientValueExtractorService,
{ provide: DOCUMENT, useValue: mockDocument },
],
});
service = getTestBed().inject(ClientValueExtractorService);
}
);
it('should give the clientValues', () => {
mockDocument.cookie = 'setting some cookie';
expect(service.getValues()).toStrictEqual(); // expecting setting cookie value but getting empty
});
tried this one to inject directly but still no luck
mockDocument = TestBed.inject(DOCUMENT);
the same test works before to have document object provided with injection token, migrating angular DI token then it breaks,
{ provide: 'Document', useValue: document },
does anyone have any idea how to fix this