Skip to content

The test init command to add a sample test in TypeScript for TypeScript/Angular projects #1798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vchimev opened this issue Jun 2, 2016 · 26 comments
Assignees
Milestone

Comments

@vchimev
Copy link

vchimev commented Jun 2, 2016

The tns test init command configures a project for unit testing, creates a tests folder in the app directory and adds an example.js file in it with a sample test.

It would be great the sample test to be in TypeScript (example.ts) for TypeScript/Angular projects.

@enchev enchev added the feature label Jun 13, 2016
@tjvantoll
Copy link
Contributor

This came up as a limitation while writing a guide on unit testing today, so I’ll toss in my vote for this feature.

@nraboy
Copy link

nraboy commented Aug 16, 2016

+1

2 similar comments
@stefalda
Copy link

+1

@kalanaw
Copy link

kalanaw commented Sep 19, 2016

+1

@tsonevn tsonevn added this to the 2.6.0 (TBD) milestone Dec 5, 2016
@JuanDelgadillo
Copy link

+1

@pkoleva pkoleva modified the milestone: 2.6.0 (TBD) Jan 26, 2017
@vstuen
Copy link

vstuen commented Jan 30, 2017

+1

3 similar comments
@scottjmchugh
Copy link

+1

@harrinsonmb
Copy link

+1

@stefanmeschke
Copy link

+1

@jacobbundren
Copy link

+1

8 similar comments
@Jai-Krish
Copy link

+1

@Roar1827
Copy link

+1

@simonox
Copy link

simonox commented Jun 8, 2017

+1

@ludcila
Copy link

ludcila commented Jul 8, 2017

+1

@agra1992
Copy link

agra1992 commented Oct 5, 2017

+1

@AresDev
Copy link

AresDev commented Oct 9, 2017

+1

@anorthwolf
Copy link

+1

@fpaaske
Copy link

fpaaske commented Feb 15, 2018

+1

@Belax8
Copy link

Belax8 commented Feb 23, 2018

@vchimev or @tjvantoll, can we get an update on this issue? Will this be worked on any time soon? Thanks!

@AresDev
Copy link

AresDev commented Mar 15, 2018

+1

@fpaaske
Copy link

fpaaske commented Mar 23, 2018

For now, here's an template/example of a .spec.ts file that works. It tests a component that requires a REST service, but that is mocked by mockito.

import {mock} from 'ts-mockito';
import * as utils from 'utils/utils';
import {ContactDetailsNSComponent} from '../contact-details/contact-details.component';
import {GtDirectoryService, ContactViewModel} from '@private/library';

describe('Contact details test', function () {
  let contactDetailsComponent;

  beforeEach(function () {

    const directoryService = mock(GtDirectoryService);
    contactDetailsComponent = new ContactDetailsNSComponent(new ContactViewModel('4799999999'), directoryService);
  });

  it('should create tel-uri when tapping call', function () {

    const spy = spyOn(utils, 'openUrl');
    contactDetailsComponent.onTapCall();
    expect(spy.calls.count()).toBe(1);
    expect(spy.calls.first().args[0]).toBe('tel:+4799999999');
  });

  it('should create sms-uri when tapping sms', function () {

    const spy = spyOn(utils, 'openUrl');
    contactDetailsComponent.onTapMessage();
    expect(spy.calls.count()).toBe(1);
    expect(spy.calls.first().args[0]).toBe('sms:+4799999999');
  });
});

@cvietor
Copy link

cvietor commented Jul 19, 2018

+2 :)

@Oatelaus
Copy link

Oatelaus commented Nov 6, 2018

In a project of entirely typescript files, it seems backwards to write JavaScript tests.
Is there any update to this, or is anyone aware of how to get my tests compiled along with tns test <platform>?

Adding karma-typescript to the karma.conf.js causes issues (Javascript running out of memory, tsconfig related conflicts, generally seems to be the wrong way to achieve this) - I can't seem to figure out how other people are writing tests in typescript (example: nativescript-angular's tests are all in typescript)

@nkalscheuer
Copy link

+2

@Fatme Fatme added this to the 5.4.0 milestone Mar 27, 2019
@Fatme
Copy link
Contributor

Fatme commented Mar 27, 2019

Currently you should be able to achieve this using the following steps:

  1. Replace example.js file with example.ts inside tests folder
  2. Change the files property in karma.conf.js
files: [
      'app/tests/**/*.ts'
],
  1. Install the required definitions for the selected testing framework
    When mocha is selected: npm i --save-dev @types/chai && npm i --save-dev @types/mocha && npm i --save-dev @types/karma-chai

We're working on improving our unit testing story and planned this issue for one of our next releases.

@cowboyd
Copy link

cowboyd commented Mar 27, 2019

This worked, but the test init command put the files in src/tests/, so we made this line in the karma.conf.js src/tests/**/*.ts

@Fatme Fatme added in progress and removed planned labels Mar 28, 2019
Fatme added a commit to NativeScript/nativescript-dev-webpack that referenced this issue Mar 29, 2019
@Fatme Fatme modified the milestones: 5.4.0, 5.3.1 Mar 29, 2019
Fatme pushed a commit to NativeScript/nativescript-dev-webpack that referenced this issue Mar 29, 2019
@rosen-vladimirov rosen-vladimirov modified the milestones: 5.3.1, 5.3.2 Apr 3, 2019
Fatme pushed a commit to NativeScript/nativescript-dev-webpack that referenced this issue Apr 3, 2019
Fatme pushed a commit to NativeScript/nativescript-dev-webpack that referenced this issue Apr 5, 2019
* release: cut the 0.21.0 release

* fix: add support for ts files on test command when `--bundle` is provided (#848)

Rel to:
NativeScript/nativescript-cli#4477
NativeScript/nativescript-cli#1798
Fatme pushed a commit to NativeScript/nativescript-dev-webpack that referenced this issue Apr 8, 2019
* release: cut the 0.21.0 release

* fix: add support for ts files on test command when `--bundle` is provided (#848)

Rel to:
NativeScript/nativescript-cli#4477
NativeScript/nativescript-cli#1798

* fix: use correct slashes on windows (#851)
Fatme pushed a commit to NativeScript/nativescript-dev-webpack that referenced this issue Apr 12, 2019
* release: cut the 0.21.0 release

* fix: add support for ts files on test command when `--bundle` is provided (#848)

Rel to:
NativeScript/nativescript-cli#4477
NativeScript/nativescript-cli#1798

* fix: use correct slashes on windows (#851)

* fix: fix "ERROR in Must have a source file to refactor." error from ngCompilerPlugin on `test` command (#859)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests