Q:

How we use TestBed for components with NativeScript?

I'm writing an app with NativeScript 6+ and Angular 8+. I'm trying to write some unit tests and get them up and running. I have read the documentation on unit testing: https://docs.nativescript.org/tooling/testing/testing I've got some unit tests up and running with plain components. e.g.
import { ItemsComponent } from "~/app/item/items.component";
import { ItemService } from "~/app/item/item.service";

describe('Items Component Standard Test', () => {

    let  component: ItemsComponent;

    beforeEach(() => {
        component = new ItemsComponent(new ItemService());
    });

    it('should be defined', () => {
        expect(component).toBeTruthy();
    });

});
});

I see that we can test Components with dependencies by instantiating them in the constructors and with mock services as well. https://angular.io/guide/testing#service-tests
I tried to follow the tutorial on this web page but I keep getting an error:
sample code & repository:
https://github.com/aquinn637/Fresh
import { ItemsComponent } from "~/app/item/items.component";
import { ItemService } from "~/app/item/item.service";
import { nsTestBedBeforeEach, nsTestBedAfterEach, nsTestBedRender } from "nativescript-angular/testing";

describe('Renderer E2E', () => {

    beforeEach(nsTestBedBeforeEach([ItemsComponent], [ItemService]));
    afterEach(nsTestBedAfterEach(false));

    it('should be defined',  () => {

        nsTestBedRender(ItemsComponent).then((fixture) => {
            expect(fixture.componentInstance).toBeTruthy();
        });

    });

Error:
CONSOLE WARN file:///node_modules/@nativescript/angular/testing/src/util.js:171:0: nsTestBedRender called without nsTestBedBeforeEach/nsTestBedAfter each. You are responsible for calling 'fixture.destroy()' when your test is done in order to clean up the components that are created.

CONSOLE ERROR file:///app/vendor.js:85281:30: Unhandled Promise rejection: 'expect' was used when there was no current spec, this could be because an asynchronous test timed out ; Zone: ProxyZone ; Task: Promise.then ; Value: Error: 'expect' was used when there was no current spec, this could be because an asynchronous test timed out ZoneAwareError(file:///node_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:1298:0)

at

at expect

at

at file:///node_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:138:0

at file:///node_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:883:0

at file:///node_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:188:0

at drainMicroTaskQueue(file:///node_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:595:0)

at file:///node_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:500:0

at timer(file:///node_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:1561:0)

at invoke(file:///node_modules/@nativescript/core/timer/timer.js:54:30)

at file:///node_modules/@nativescript/angular/zone-js/dist/zone-nativescript.js:151:0

at file:///node_modules/@nativescript/core/timer/timer.js:18:0

at UIApplicationMain([native code])

at run(file:///node_modules/@nativescript/core/application/application.js:312:0)

at ../node_modules/nativescript-unit-test-runner/app/bundle-app.js(file:///node_modules/nativescript-unit-test-runner/app/bundle-app.js:3:0)

at __webpack_require__(file:///src/webpack/bootstrap:74:0)

at file:///src/main.ts:11:16

at ./main.ts<…>

19 03 2020 12:01:11.660:WARN [NativeScript / 13.3 (13.3; iPad)]: Disconnected (0NativeScript / 13.3 (13.3; iPad) ERROR

  DisconnectedClient disconnected from CONNECTED state (transport error)

NativeScript / 13.3 (13.3; iPad): Executed 4 of 4 SUCCESS (0.161 secs / 0.099 secs)

Is it possible to use TestBed for our components in NativeScript? If so, can you provide an eample of how to do that?

A:

You are suppose to return the promise,
it("should be defined", () => {
    return nsTestBedRender(ItemsComponent).then(fixture => {
        expect(fixture.componentInstance).toBeTruthy();
    });
});

