it("throws correct error when current operating system is not supported", async () => { const invalidPlatform = "invalid_platform"; const testInjector = createTestInjector(invalidPlatform); const net = testInjector.resolve<INet>(Net); await assert.isRejected(net.waitForPortToListen({ port: 18181, timeout: 50, interval: 1 }), `Unable to check for free ports on ${invalidPlatform}. Supported platforms are: darwin, linux, win32`); });
it("fails when the templateVersion is invalid", async () => { const notSupportedVersionString = "not supported version"; const testInjector = createTestInjector({ packageJsonContent: { nativescript: { templateVersion: notSupportedVersionString } } }); const projectTemplatesService = testInjector.resolve<IProjectTemplatesService>("projectTemplatesService"); const expectedError = format(constants.ProjectTemplateErrors.InvalidTemplateVersionStringFormat, `tns-template-hello-world-ts@${compatibleTemplateVersion}`, notSupportedVersionString); await assert.isRejected(projectTemplatesService.prepareTemplate("typescript", "tempFolder"), expectedError); });
const assertThrows = async (methodName: string): Promise<void> => { const instance: any = new InvokeBeforeDecoratorsTest(); assert.isFalse(instance.isInvokeBeforeMethodCalled); const expectedResult = 1; await assert.isRejected(instance[methodName](expectedResult), expectedResult); assert.isTrue(instance.isInvokeBeforeMethodCalled); };
it("should setup manually when cloud extension is installed", async () => { mockDoctorService( { canExecuteLocalBuild: false, mockSetupScript: true }); mockPrompter({ firstCallOptionName: PlatformEnvironmentRequirements.LOCAL_SETUP_OPTION_NAME, secondCallOptionName: PlatformEnvironmentRequirements.MANUALLY_SETUP_OPTION_NAME }); mockNativeScriptCloudExtensionService({ isInstalled: true }); await assert.isRejected(platformEnvironmentRequirements.checkEnvironmentRequirements(platform), manuallySetupErrorMessage); });
it("throws correct error when null is passed", async () => { const invalidPlatform = "invalid_platform"; const testInjector = createTestInjector(invalidPlatform); const net = testInjector.resolve<INet>(Net); await assert.isRejected(net.waitForPortToListen(null), "You must pass port and timeout for check."); });
it('should throw Error', () => { // TODO: create new route with no post route defined assert.isRejected( Promise.resolve( helloRoute.parse({ url: 'spy' }, new MockReq({ method: 'POST' }), null) ) ); });
it("validate method throws", async () => { let project: Project.IProject = testInjector.resolve("project"); project.capabilities.canChangeFrameworkVersion = false; mobileFwCP = new setVersionFile.MobileFrameworkCommandParameter(testInjector.resolve("cordovaMigrationService"), testInjector.resolve("project"), testInjector.resolve("errors"), testInjector.resolve("nativeScriptMigrationService"), testInjector.resolve("projectConstants")); await assert.isRejected(mobileFwCP.validate("1.0.0"), "You cannot change FrameworkVersion of \'Cordova\' project."); });
it("should show prompt when environment is not configured and nativescript-cloud extension is installed", async () => { mockDoctorService({ canExecuteLocalBuild: false }); mockPrompter({ firstCallOptionName: PlatformEnvironmentRequirements.CLOUD_SETUP_OPTION_NAME }); mockNativeScriptCloudExtensionService({ isInstalled: true }); await assert.isRejected(platformEnvironmentRequirements.checkEnvironmentRequirements(platform)); assert.isTrue(promptForChoiceData.length === 1); assert.deepEqual("To continue, choose one of the following options: ", promptForChoiceData[0].message); assert.deepEqual(['Try Cloud Operation', 'Configure for Local Builds', 'Skip Step and Configure Manually'], promptForChoiceData[0].choices); });
it("should bubble up that error", async () => { const fakeError = new Error(s.random.string()); sinon.stub(memoryStub, "set").callsFake(() => { throw fakeError; }); await assert.isRejected(bucket.get(key, name), fakeError.message); memoryStub.set.restore(); });
it("fails with correct error when the destination stream raises error event", async () => { const pacoteService = setupTest(); const pacoteExtractPackagePromise = pacoteService.extractPackage(packageName, destinationDir); setImmediate(() => { tarExtractDestinationStream.emit("error", new Error(errorMessage)); }); await assert.isRejected(pacoteExtractPackagePromise, errorMessage); });