google / intermock

Mocking library to create mock objects with fake data for TypeScript interfaces
https://google.github.io/intermock/
Apache License 2.0
1.13k stars 71 forks source link

No mock of heritage attributes in an attribute of a type that has inheritance #2

Open luisgurmendez opened 5 years ago

luisgurmendez commented 5 years ago

There is an issue when mocking attributes of interfaces that have inheritance. Example file:

interface A{
   a: string
}

interface BA extends A{
   b: string
}

interface C{
   ba: BA
   c: string
}

Output:


interface A{
   a: string
}

interface BA extends A{
   b: string
}

interface C{
   ba: BA
   c: string
}

{
  "C": {
    "ba": {
      "b": "Suscipit corrupti id dicta dolores assumenda eum magni officia omnis. Consectetur minus qui occaecati odio repellat sunt et occaecati. Ex nulla explicabo. Eius quasi dicta et et nesciunt. Maiores sed molestiae voluptas fugit cumque omnis mollitia rerum illo. Repellat est atque recusandae nihil tempora iure."
    },
    "c": "Quia voluptatem minima nemo velit.\nPraesentium ut aut."
  }
};

There is no 'a' attribute on the output. I think that the issue comes from the gatherTypes function

ryanmcdermott commented 5 years ago

Thanks for filing this! There's a specific test for this transformation but I think internal property types of an interface that also extend a type are not getting mocked properly.

https://github.com/google/intermock/blob/master/test/ts/test-data/extension.ts