moleculer-template-project-typescript icon indicating copy to clipboard operation
moleculer-template-project-typescript copied to clipboard

Default tests are not working

Open renegat59 opened this issue 4 years ago • 12 comments

Hi, after generating the project with project-typescript template and running npm run test I'm getting errors. Most of them I managed to solve as they were just syntax issues, but one bothers me and I can't figure out what's the problem.

FAIL  test/unit/services/products.spec.ts
  ● Test 'products' service › Test hooks › Test before 'create' hook › should add quantity with zero

    expect(jest.fn()).toBeCalledTimes(expected)

    Expected number of calls: 1
    Received number of calls: 0

      179 |         });
      180 | 
    > 181 |         expect(createActionFn).toBeCalledTimes(1);
          |                                ^
      182 |         expect(createActionFn.mock.calls[0][0].params).toEqual({
      183 |           id: "111",
      184 |           name: "Test product",

      at test/unit/services/products.spec.ts:181:32
      at fulfilled (test/unit/services/products.spec.ts:5:58)

When I debug it, the method is called with corect values. But when testing it says it's not. I was also trying to debug the parseServiceSchema and I can't find there where the hooks are applied to the service so I can't really test if the mock function is correctly assigned. Any idea what is the solution?

renegat59 avatar Sep 25 '20 11:09 renegat59

I see your problem like #35 I was fix it with PR #36 Can you confirm it?

oanhnn avatar Oct 05 '20 05:10 oanhnn

using last version.

devalexandre avatar Apr 03 '21 14:04 devalexandre

which latest version

bashiru98 avatar Aug 06 '21 09:08 bashiru98

my tests are not also passing and am getting hard time to fix it

bashiru98 avatar Aug 06 '21 09:08 bashiru98

@bashiru98 what's the error that you're getting?

I've done a fresh install and got one like this: image

I'm not a TS guy but I think it's related to the https://github.com/moleculerjs/moleculer/pull/980

AndreMaz avatar Aug 06 '21 09:08 AndreMaz

@AndreMaz yes, I believe that issue should be fixed by the referenced PR.

shawnmcknight avatar Aug 06 '21 11:08 shawnmcknight

@AndreMaz I go reinstall and try, but the moleculerjs/moleculer#980 not resolve it

devalexandre avatar Aug 06 '21 13:08 devalexandre

@AndreMaz I go reinstall and try, but the moleculerjs/moleculer#980 not resolve it

I'm guessing that moleculerjs/moleculer#980 isn't working here because the tsconfig in this repo doesn't appear to have noImplicitThis set to true. The ThisType utility type requires that to be turned on in order to function.

shawnmcknight avatar Aug 06 '21 13:08 shawnmcknight

@shawnmcknight it's work :)

image

devalexandre avatar Aug 06 '21 14:08 devalexandre

@bashiru98 what's the error that you're getting?

I've done a fresh install and got one like this: image

I'm not a TS guy but I think it's related to the moleculerjs/moleculer#980

exactly same error

bashiru98 avatar Aug 08 '21 12:08 bashiru98

I think its a TS config error

bashiru98 avatar Aug 08 '21 12:08 bashiru98

Guys about the uncovered lines how do we solve it

bashiru98 avatar Aug 08 '21 12:08 bashiru98