I'm trying to write a unit test and I'm getting this error.
TypeError: Cannot read property 'pipe' of undefined at Jasmine
const mockServiceObj = jasmine.createSpyObj < FormRegistrationService > (["registerForm", "pipe"]);
const getCurrentSystemPreference = jasmine.createSpyObj < CurrentSystemPreferencesService > ([
"getCurrentSystemPreference",
"pipe",
]);
function getServiceManagerLinks(): ServiceManagerSharedLinksComponent {
return new ServiceManagerSharedLinksComponent(null, mockServiceObj, getCurrentSystemPreference);
}
Probably the correct (or at least close to correct) unit tests approach for your situation.
You have
currentSystemPreferencesService
const and provide it toproviders
. Now it's accessible in all tests cases. You also providegetPreferences
field as callable method. Andof(true)
means you return onObservable
which is needed forpipe()
in real code since you immediately call.pipe(...)
after callinggetPreferences(SystemPreference.APITestValue)