angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

`ng g config` to generate `test.ts`

Open cexbrayat opened this issue 2 years ago • 3 comments

Command

test

Description

It is possible to generate the karma.conf.js file but not to generate the test.ts file.

This file can be really useful to add things like custom matchers.

Describe the solution you'd like

Something like ng g config test that would re-add the test.ts file to the project, allowing to customize it.

I have a WIP PR to add this if the team is OK.

Describe alternatives you've considered

You can manually add the file if you know how it should look.

Or maybe we could have an extra field in the karma builder like 'setup', to just specify a file that would add the custom matchers.

cexbrayat avatar Nov 26 '23 17:11 cexbrayat

Hi @cexbrayat,

What would you like to customize in the test.ts?

alan-agius4 avatar Nov 27 '23 07:11 alan-agius4

as I mentioned in the issue, it can be useful to add custom Jasmine matchers to all tests, for example:

beforeEach(() => {
  jasmine.addMatchers(customMatchers);
});

cexbrayat avatar Nov 27 '23 07:11 cexbrayat

I'll add another use case: in the upcoming zoneless experiment, it will be handy to add provideExperimentalZonelessChangeDetection() into initTestBed. A way to add test.ts back into the project would simplify that.

cexbrayat avatar May 06 '24 17:05 cexbrayat