Search code examples
angulartypescriptjasminengxs

Jasmine withArgs expected types


I have been going through and upgrading my angular version from 10 to 13. So that I could use typescript 4.6. In doing this, I screwed up some types in my tests and was curious if anyone else has experienced this. The error I am getting is:

Argument of type '(state: ExampleStateModel) => Example' is not assignable to parameter of type 'StateToken<unknown> | AsymmetricMatcher<any>'.ts(2345)

I can get all my tests to compile and run by just using: @ts-ignore but I would like to avoid that as my solution if I can. Here is some code

fails

 store = TestBed.inject(Store);
 spyOn(store, 'selectSnapshot')
   .withArgs(ExampleState.clinic).and.returnValue({ id: 1 })

works

 store = TestBed.inject(Store);
 // @ts-ignore
 spyOn(store, 'selectSnapshot').withArgs(ExampleState.clinic).and.returnValue({ id: 1 })

Example State

@Injectable()
export class ExampleState {
  @Selector()
  public static clinic(state: ExampleStateModel) {
    return state.clinic;
  }
}

I have also tried running npm i -D jasmine@latest jasmine-core@latest @types/jasmine@latest

I guess my question boils down how to use withArgs() using a ngxs store. Any help is appreciated.


Solution

  • I ended up just going with @ts-ignore. Playing around with the correct versions on all my packages became too big of a headache when @ts-ignore just works.