moleculerjs / moleculer-template-project-typescript

Typescript project template for Moleculer microservices framework.
MIT License
124 stars 45 forks source link

Default tests are not working #37

Closed renegat59 closed 1 year ago

renegat59 commented 4 years ago

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?

oanhnn commented 4 years ago

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

devalexandre commented 3 years ago

using last version.

bashiru98 commented 3 years ago

which latest version

bashiru98 commented 3 years ago

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

AndreMaz commented 3 years ago

@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

shawnmcknight commented 3 years ago

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

devalexandre commented 3 years ago

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

shawnmcknight commented 3 years ago

@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.

devalexandre commented 3 years ago

@shawnmcknight it's work :)

image

bashiru98 commented 3 years ago

@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 commented 3 years ago

I think its a TS config error

bashiru98 commented 3 years ago

Guys about the uncovered lines how do we solve it