ionic-mocks icon indicating copy to clipboard operation
ionic-mocks copied to clipboard

Make compatible with Jest

Open russcarver opened this issue 8 years ago • 6 comments

This is some great stuff! However we have recently migrated from Karma to Jest and Jest does not expose the createSpyObj method of Jasmine. As such, I've had to "copy" over the mocks you have that I want to use and have them use this version of `createSpyObj'. If you could incorporate it somehow into your code, that would be great!!

export function  createSpyObj (baseName: string, methodNames: string[]): { [key: string]: jasmine.Spy } {
  const obj: any = {}
  for (let i: number = 0; i < methodNames.length; i++) {
    obj[methodNames[i]] = jasmine.createSpy(baseName, () => {})
  }
  return obj
}

russcarver avatar Aug 01 '17 19:08 russcarver

@russcarver thanks for the issue. I've never used Jest but I'll have a look.

stonelasley avatar Aug 02 '17 02:08 stonelasley

+1 on this, Id love to use your mocks but using jest is painful with it.

MagicAardvark avatar Oct 09 '17 15:10 MagicAardvark

@russcarver @MagicAardvark do either of you have a public project that is using jest that I could clone and tinker with?

stonelasley avatar Oct 09 '17 16:10 stonelasley

I do not currently, Jest is very very simple to set up. as a temporary fix I can offer a 'fix' I made to your code to use @russcarver's suggestion above. ill open a PR for you.

MagicAardvark avatar Oct 09 '17 16:10 MagicAardvark

@MagicAardvark, thank you.

stonelasley avatar Oct 09 '17 16:10 stonelasley

https://github.com/stonelasley/ionic-mocks/pull/31

MagicAardvark avatar Oct 09 '17 16:10 MagicAardvark