I have a NativeScript Code-Sharing project. I wish to use Karma unit testing against the web version using ng test. This fails due to a .tns version of a service being wrongly imported when building the tests.
Following are steps to recreate the problem in a minimal NativeScript Code-Sharing project.
- Create a new NativeScript Code-Sharing project - $ ng new -c=@nativescript/schematics ns-shared-test --shared
- Enter the project folder - $ cd ns-shared-test
- Generate a new service - $ ng generate service services/my-service
- Generate a new component - $ ng generate component my-component
- Modify - my-component.component.tsto use my-service- Add at top of file: - import { MyServiceService } from '@src/app/services/my-service.service';
- And replace the constructor: - constructor( private myService:MyServiceService ) { }
 
- Run unit tests - $ ng test- Observe that the test passes
 
- Split my-service - $ cp src/app/services/my-service.service.ts src/app/services/my-service.service.tns.ts
- Modify - my-service.service.tns.tsto use something NativeScript specific- Add at the top of file: - import { Color } from 'tns-core-modules/color/color';
- And replace the constructor: - constructor() { new Color('white'); }
 
- Run unit tests - $ ng test- Observe that the test fails while loading NativeScript modules
 
 
    