If you know how to fix the issue, make a pull request instead.
@types/xxxx package and had problems.Definitions by: in index.d.ts) so they can respond.jasmine.createSpyObj takes an array of property names as a parameter following the array of method names.
Merged to master 27 days ago in https://github.com/jasmine/jasmine/pull/1722
Maybe included in the package version bump 15 days ago?
This also accepts an object where each object property value becomes the value of the property defined on the mock.
@rcollette New version of jasmine has not been published yet. Let's wait for the release before updating typings.
FYI: Jasmine 3.5.0 is out
which includes this feature: "Allow users to pass property names to createSpyObj"
Hi @rcollette @zvirja @HonoluluHenk The types for 3.5.0 have been released. Please try them out to see if I've added them correctly.
createSpyObj
createSpyObj<T>('name',[],{prop1:'value'})
but the type declaration seems to be forcing me to specify an array of property names, unless T is undefined.
I wound up having to do:
authorizationService = createSpyObj('authorizationService', [], { principal$ });
@rcollette Could you change the types in your node_modules so the SpyObjPropertyNames is:
type SpyObjPropertyNames<T = undefined> =
T extends undefined ?
(ReadonlyArray<string> | { [propertyName: string]: any }) :
(ReadonlyArray<keyof T>) | { [P in keyof T]?: any });;
Sorry for the delay... work priorities.
I corrected the declaration to (note there was an extra paren and semicolon):
type SpyObjPropertyNames<T = undefined> =
T extends undefined ?
(ReadonlyArray<string> | { [propertyName: string]: any }) :
(ReadonlyArray<keyof T>) | { [P in keyof T]?: any };
Using:
principal$ = new Subject<IPrincipal>();
authorizationService = createSpyObj<AuthorizationService>('authorizationService', [], { principal$ });
I get the following error.
Error:(22, 93) TS2345: Argument of type '{ principal$: Subject
; }' is not assignable to parameter of type 'ReadonlyArray<"authenticated$" | "principal$" | "isAuthenticated$">'.
Object literal may only specify known properties, and 'principal$' does not exist in type 'ReadonlyArray<"authenticated$" | "principal$" | "isAuthenticated$">'.
I see that you've included an object in that declaration but it does not get picked up for some reason.
Most helpful comment
FYI: Jasmine 3.5.0 is out
which includes this feature: "Allow users to pass property names to createSpyObj"