angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.77k stars 11.98k forks source link

Generate .spec files for already existing components / services #7727

Closed smnbbrv closed 4 years ago

smnbbrv commented 7 years ago

Solution

If you look for right now solution please follow ngx-spec.

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Versions.

@angular/cli: 1.4.2 node: 8.1.3 os: darwin x64 @angular/animations: 4.3.6 @angular/common: 4.3.6 @angular/compiler: 4.3.6 @angular/core: 4.3.6 @angular/forms: 4.3.6 @angular/http: 4.3.6 @angular/platform-browser: 4.3.6 @angular/platform-browser-dynamic: 4.3.6 @angular/router: 4.3.6 @angular/cli: 1.4.2 @angular/compiler-cli: 4.3.6 typescript: 2.4.2

Repro steps.

The log given by the failure.

Desired functionality.

I want to generate a .spec file for already existing component / service that does not have a spec yet / has an outdated spec. More on the usecase https://stackoverflow.com/q/46276055/1990451

Mention any other details that might be useful.

smnbbrv commented 7 years ago

A small addition: would be incredibly perfect if the just created .spec.ts files would have mocks for the every injected item according to the methods / properties that are used in the unit being tested :)

Brocco commented 7 years ago

Right now, specs are directly tied to the unit they're testing (component/service) and as of now there are no plans to support this, but leaving this open for discussion purposes.

frontEndExpert commented 6 years ago

Yes generating a spec file after we already generated our component and modified it. ng g component your-component --spec-only

michaelbazos commented 6 years ago

What I do to generate the spec file for an already existing component:

ng generate component [name]

And then answer "no" to the "Overwrite ..." questions regarding already existing, non-spec, files.

EDIT: this is not possible in the current version (1.6.0) of angular-cli, as it would prompt the component already exists and would not generate any file.

darkbasic commented 6 years ago

@michaelbazos it doesn't work, it simply notifies that the component already exists.

tomwhite007 commented 6 years ago

I'd like to add my vote for this. Even if it was only able to create the "[object] works!" type test, it would still save on boilerplate.

michaelbazos commented 6 years ago

@darkbasic Indeed, just updated my version of angular-cli to 1.6.0, and it seems no file is generated if any of the [component | template | spec | stylesheet] already exists. Previously I was on 1.4.x, and it used to create non existing files, and ask for already existing ones.

smnbbrv commented 6 years ago

So, it's a misdocumented feature then? @Brocco can you confirm it's the right way to do stuff?

BBaysinger commented 6 years ago

Also, say I have an entire project w/o .spec files. There should be a way to create them all from a single command.

AngelZatch commented 6 years ago

Agreeing with this. I'm currently reconstructing a project and the previous devs manually deleted spec files, my afternoon's very long.

Afbcary commented 6 years ago

+1 from me. Refactoring unconventional tests to work with Wallaby and could really use this feature.

19Arne75 commented 6 years ago

+1

dakipro commented 6 years ago

+1

manytostao-zz commented 6 years ago

+1

HannaBabrouskaya commented 6 years ago

+1

MartinPospieszczyk commented 6 years ago

+1

FreedomRings commented 6 years ago

+1

cipas commented 6 years ago

+1

GuiOttoni commented 6 years ago

+1

smnbbrv commented 6 years ago

I created a pull request implementing the feature https://github.com/angular/devkit/pull/938 .

Allows to create specs for component, directive, module, service, pipe, guard (based on corresponding schematics) by running

ng g spec my-component.component

or as a file (more convenient because files normally already exist and it is easier to point to the file)

ng g spec /my/project/app/src/blah/my-component.component.ts

Please review.

PCASME commented 6 years ago

+1

aoganezo commented 6 years ago

+1

tgrkzus commented 6 years ago

For anyone still looking for a solution to this: https://www.npmjs.com/package/angular-spec-generator

This seemed to work fairly well for me.

smnbbrv commented 6 years ago

As an outcome of the pull request: the custom schematic as a standalone library ngx-spec. Please check and share your feelings there.

@Brocco I leave the thread open as a reference for the future RFC / standard.

MrTaiji commented 6 years ago

+1 I think this should be possible without installing a additional node package

gilupu commented 6 years ago

+1 I think this should be possible without installing a additional node package

appienvanveen commented 6 years ago

+1

koolkav1 commented 6 years ago

+1

ryankazokas commented 5 years ago

+1

median-man commented 5 years ago

+1

neilsoult commented 5 years ago

+my whole dev team

gustavshf commented 5 years ago

+1

mosermanuel commented 5 years ago

+1

dylanwooters commented 5 years ago

+1

mosermanuel commented 5 years ago

Ich bin derzeit nicht im Büro. Ich kehre zurück am 10.01.2019. Ich werde Ihre Nachricht nach meiner Rückkehr beantworten.

Bei dringenden Angelegenheiten bitte an folgende Personen wenden:

Webframework: Gernot Binder Widgetsystem: Rainer Neunteufel Mein ELBA Architektur: Peter Anderle Mein ELBA ZVKK: Gerhard Weinberger PSD2: Harald Mülleder

Die Rückmeldung bezieht sich auf ein Mail mit folgendem Thema: Re: [angular/angular-cli] Generate .spec files for already existing components / services (#7727)


Gesendet (c) GRZ/RACON Linz 2019 Agent 'Abwesenheit'


Raiffeisen Software GmbH Firmenbuchnummer: 86804d, Landesgericht Linz DVR: 0572934, UID: ATU 36961105

Der Austausch von Nachrichten mit dem oben angeführten Absender via E-Mail dient ausschließlich Informationszwecken. Rechtsgeschäftliche Erklärungen dürfen über dieses Medium nicht ausgetauscht werden. Correspondence with above mentioned sender via e-mail is only for information purposes. This medium is not to be used for the exchange of legally-binding communications.

nukithelegend commented 5 years ago

+1

fyllepo commented 5 years ago

+1 why does this not exist...

joaop221 commented 5 years ago

+1

EdWood1994 commented 5 years ago

+1

Menion93 commented 5 years ago

+1

mosermanuel commented 5 years ago

Ich bin derzeit nicht im Büro. Ich kehre zurück am 02.05.2019. Ich werde Ihre Nachricht nach meiner Rückkehr beantworten.

Bei dringenden Angelegenheiten bitte an folgende Personen wenden:

Webframework: Gernot Binder Widgetsystem: Rainer Neunteufel Mein ELBA Architektur: Peter Anderle Mein ELBA ZVKK: Gerhard Weinberger PSD2: Harald Mülleder

Die Rückmeldung bezieht sich auf ein Mail mit folgendem Thema: Re: [angular/angular-cli] Generate .spec files for already existing components / services (#7727)


Gesendet (c) GRZ/RACON Linz 2019 Agent 'Abwesenheit'


Raiffeisen Software GmbH Firmenbuchnummer: 86804d, Landesgericht Linz DVR: 0572934, UID: ATU 36961105

Der Austausch von Nachrichten mit dem oben angeführten Absender via E-Mail dient ausschließlich Informationszwecken. Rechtsgeschäftliche Erklärungen dürfen über dieses Medium nicht ausgetauscht werden. Correspondence with above mentioned sender via e-mail is only for information purposes. This medium is not to be used for the exchange of legally-binding communications.

stevewithington commented 5 years ago

I realize this thread is a bit dated, however I've just run into this myself (wishing for a ng g spec type of functionality). That said, if anyone else runs across this and is looking for a simple way to do this, I've found this project to fill the hole for now https://github.com/allenhwkim/ngentest

newmediapilot commented 5 years ago

Something I do is... generate component COMPONENT-NAME --force then in GIT revert the items that got overwritten

nukec commented 5 years ago

this simple thing still not in?

mosermanuel commented 5 years ago

Ich bin derzeit nicht im Büro. Ich kehre zurück am 08.07.2019. Ich werde Ihre Nachricht nach meiner Rückkehr beantworten.

Die Rückmeldung bezieht sich auf ein Mail mit folgendem Thema: Re: [angular/angular-cli] Generate .spec files for already existing components / services (#7727)


Gesendet (c) GRZ/RACON Linz 2019 Agent 'Abwesenheit'


Raiffeisen Software GmbH Firmenbuchnummer: 86804d, Landesgericht Linz DVR: 0572934, UID: ATU 36961105

Der Austausch von Nachrichten mit dem oben angeführten Absender via E-Mail dient ausschließlich Informationszwecken. Rechtsgeschäftliche Erklärungen dürfen über dieses Medium nicht ausgetauscht werden. Correspondence with above mentioned sender via e-mail is only for information purposes. This medium is not to be used for the exchange of legally-binding communications.

tijujohn83 commented 5 years ago

+1

kmanev073 commented 5 years ago

+1

afnecors commented 5 years ago

+1

sscots commented 5 years ago

+1

samuelzapote commented 5 years ago

+1 & +whole dev team