Typescript-TDD / ts-auto-mock

Typescript transformer to unlock automatic mock creation for interfaces and classes
https://typescript-tdd.github.io/ts-auto-mock
MIT License
601 stars 16 forks source link

Karma hot reloading error #610

Open BrunoBeraudPW opened 3 years ago

BrunoBeraudPW commented 3 years ago

Subject of the issue

Hello !

Seems similar to https://github.com/Typescript-TDD/ts-auto-mock/issues/105

First, I have registered a type for all my tests files in test.ts Second, in app.component.spec I have added a test which use createMock function Then, when I launch the jasmine tests, it's ok for the first execution, but for the next ones using the hot reloading this test will fail because of an internal error raise in the library : ts_auto_mock_repository__WEBPACK_IMPORTED_MODULE_1__.ɵRepository.instance.getFactory(...) is not a function image

Your environment

https://github.com/BrunoBeraudPW/issue-ts-auto-mock Angular last version default configuration ts-patch last version with cache enabled

Steps to reproduce

npm run install npm run test trigger the hot reloading in saving app.component.spec

Thank a lot !

uittorio commented 3 years ago

hi @BrunoBeraudPW, thank you for creating a new issue. First of all, thank you again @Pmyl for investigating the issue and writing down all the possible solutions. After a quick chat, we've realized that the only way to support registerMock in live reload is with the cache disabled. Unfortunately, the option in the transformer configuration is not enough right now to support this functionality because registerMock is still configured in your 'main.ts' file. We are planning to write some code that will copy the registerMock initialisation in each of the tests that use createMock.

Current workaround?

Move the registerMock in each of your tests file that uses directly or indirectly the interface that you want to register.

Thanks again. @Pmyl feel free to add more details

BrunoBeraudPW commented 3 years ago

Understood ! Thank for your answer and your time for investigation