Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS error on a specific class mock #282

Closed
C0ZEN opened this issue Mar 30, 2020 · 6 comments
Closed

TS error on a specific class mock #282

C0ZEN opened this issue Mar 30, 2020 · 6 comments
Assignees

Comments

@C0ZEN
Copy link
Contributor

C0ZEN commented Mar 30, 2020

Subject of the issue

When using createMock on a specific complex class, an error occurred breaking all the tests.

Your environment

  • ts-auto-mock version: 1.5.7
  • typescript version: 3.8.3
  • node version: 13.5.0
  • npm version: 6.14.2
  • ttypescript: 1.5.10
  • jest-ts-auto-mock: 1.0.11
  • jest: 25.2.4
  • discord.js: 12.1.1

Steps to reproduce

import { Message } from 'discord.js';

createMock<Message>();

You can also checkout the online version of the problem but note that the tests are not working with the dependencies so this is only to have a look of the dependencies and the test not working.

StackTrace

TypeError: Cannot read property 'declarations' of undefined

at r (node_modules/ts-auto-mock/transformer/index.js:176:21)
at Object.t [as GetDeclarationFromNode] (node_modules/ts-auto-mock/transformer/index.js:172:16)
at node_modules/ts-auto-mock/transformer/index.js:550:38
at Array.forEach (<anonymous>)
at node_modules/ts-auto-mock/transformer/index.js:549:17
at Array.forEach (<anonymous>)
at p (node_modules/ts-auto-mock/transformer/index.js:548:46)
at l (node_modules/ts-auto-mock/transformer/index.js:542:41)
at Object.t.CreateMockFactory (node_modules/ts-auto-mock/transformer/index.js:561:59)
at Object.t.GetTypeReferenceDescriptor (node_modules/ts-auto-mock/transformer/index.js:960:188)

Expected behavior

No error and a mock produced.

Actual behavior

Error and no mock produced.

Additional information

Could be related to the #201 issue.

Copy link
Contributor Author

C0ZEN commented Mar 30, 2020

<@U010ZUZQPS4> morning!. I confirm that there is an issue mocking Message. The interface it's actually quite complex.
View in Slack

@uittorio
Copy link
Member

uittorio commented Apr 10, 2020

Hi, good news. I've found the source of the bug.


declare function TestFn(): new (...args: any[]) => Test ;

class Test extends TestFn() {
  public a: string;
}

We don`t currently support extending function constructor.

I've found a fix, just need to add more tests to make sure we are covering all the scenarios.

@uittorio uittorio self-assigned this Apr 10, 2020
@uittorio
Copy link
Member

I've created a branch. Once it's reviewed and merge, a new version will be published :). #296

@uittorio
Copy link
Member

This is fixed in 1.6.0 :) I'll close for now. Feel free to reopen it if it's still bugged.

@C0ZEN
Copy link
Contributor Author

C0ZEN commented Apr 11, 2020

@uittorio I refactored all the Discord classes with createMock and for all the cases this new version is fine.
Thank you for the time and the fix, this is very nice.

@uittorio
Copy link
Member

Cool! bear in mind that some types are not working in discord.. it will convert to null :) hopefully it will not impact your code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants