Closed smnbbrv closed 4 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 :)
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
+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
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
+1
+1
+1
+1
+1 & +whole dev team
Solution
If you look for right now solution please follow ngx-spec.
Bug Report or Feature Request (mark with an
x
)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.