a p
a p

Reputation: 1271

Is it possible to generate a .spec file for already generated component in angular

I understand that angular-cli by default creates a .spec file for any component we create through it. But, by any chance is it possible to generate only the .spec file if one is deleted mistakenly.

I tried some one suggestion -

ng g c <component_name> --spec-only but it doesn't work.

Note - Without using any other npm modules (if available).

Upvotes: 10

Views: 10973

Answers (1)

rmcsharry
rmcsharry

Reputation: 5562

** UPDATE Jul 2018 ** There is now a 3rd party library that reportedly solves this issue here.

**NOTE - original answer **

This is a workaround that will create the .spec file as it WOULD have been created when you first generated the component. So it won't regenerate the exact file you mistakenly deleted, only the original version.

The ng c command only creates boilerplate code, so you can use it by doing a workaround, but it will only create the 'virgin boilerplate' of a new component. To do that you first need to go into a different folder (eg. create a new folder somewhere else, which you can delete afterwards) and then run the same command.

ng g c <component_name>

Delete all the files except the spec file, then copy the spec file to the original components folder and update the paths in the generate script to the correct depth (../ etc)

Upvotes: 2

Related Questions