SAP Spartacus only performs small tricks for specified unit tests

Take ng test storefrontlib as an example. If you find that the unit test you developed has a problem and needs to be debugged, you can make Angular run only the unit test that has the problem:

Modify the test.ts under the storefrontlib project folder src and change it to the following content:

// This file is required by karma.conf.js and loads recursively all the .spec and framework files

import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
import '@angular/localize/init';

declare const require: any;

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.

const FILE = ['./cms-components/checkout/components/delivery-mode/delivery-mode.component.spec.ts'];

context.keys().filter( name => !!FILE.includes(name)).map(context);

This achieves the effect we want:

For more original articles by Jerry, please follow the public account "Wang Zixi":

Guess you like

Origin blog.csdn.net/i042416/article/details/109057689