If you look for right now solution please follow ngx-spec.
x
)- [ ] bug report -> please search issues before submitting
- [x] feature request
@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
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
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 :)
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.
Yes generating a spec file after we already generated our component and modified it.
ng g component your-component --spec-only
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.
@michaelbazos it doesn't work, it simply notifies that the component already exists.
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.
@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.
So, it's a misdocumented feature then? @Brocco can you confirm it's the right way to do stuff?
Also, say I have an entire project w/o .spec files. There should be a way to create them all from a single command.
Agreeing with this. I'm currently reconstructing a project and the previous devs _manually deleted_ spec files, my afternoon's very long.
+1 from me. Refactoring unconventional tests to work with Wallaby and could really use this feature.
+1
+1
+1
+1
+1
+1
+1
+1
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.
+1
+1
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.
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.
+1
I think this should be possible without installing a additional node package
+1
I think this should be possible without installing a additional node package
+1
+1
+1
+1
+my whole dev team
+1
+1
+1
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
+1
+1 why does this not exist...
+1
+1
+1
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
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
Something I do is...
generate component COMPONENT-NAME --force
then in GIT revert the items that got overwritten
this simple thing still not in?
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
+1
+1
+1
+1
+1 & +whole dev team
I found I wanted to do this. In the end I just generated a new component with a spec called something very similar to the real component, then renamed the spec, search & replaced the content and deleted the new component.
+1
+1
This feature is currently not on our roadmap.
At the same time though, folks from community implemented a fantastic schematic which scaffolds .spec
file for existing components, discovers and mocks their dependencies. There's also a VSCode extension that you can take advantage of. You can find the project together with installation instructions here.
There's also a schematic from the author of the issue that you can give a try to.
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
_This action has been performed automatically by a bot._
Most helpful comment
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
or as a file (more convenient because files normally already exist and it is easier to point to the file)
Please review.