GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Allow using `vi.mock` (and related) functions in tests · Issue #32641 · angular/angular-cli Open Milestone DescriptionWhich @angular/* package(s) are relevant/related to the feature request?core DescriptionWith the new Angular unit-test builder (Vite), test files are bundled into unified chunks.
Currently if we use TestBed overrides are insufficient because:
Proposed solutionInstead of runtime interception (like Vitest normally does), Angular test builder should:
I suggest to create esbuild plugin, that:
Example Transform InjectableBefore: import { MyService } from './my-service'; import { MyOtherService } from './my-other-service'; vi.mock('./my-service', () => ({ MyService: @Injectable({providedIn: 'root'}) class { get() { return 'mock'; } } })); vi.mock('./my-other-service'); test(() => { const myService = new MyService(); const myOtherService = new MyOtherService(); }); After: // should initialize once in one environment const __angularViMocks = (globalThis.__angular_vi_mocks ??= new Map<string, any>()); __angularViMocks.set( './my-service', (() => ({ MyService: class { get() { return 'mock'; } static ɵprov = { providedIn: 'root', factory: () => new this(); }; static ɵfac = () => new this(); } }))() ); __angularViMocks.set( './my-other-service', (() => ({ MyOtherService: class { get = vi.fn(); // maybe better to put `vi.fn()` to MyOtherService.prototype.get = vi.fn(); static ɵprov = { providedIn: 'root', factory: () => new this(); }; static ɵfac = () => new this(); } }))() ); import * as __angularViActualMod1 from './my-service'; import * as __angularViActualMod2 from './my-other-service'; // We should replace that import in every dependent chunk. const { MyService } = __angularViMocks.get('./my-service') ?? __angularViActualMod1; const { MyOtherService } = __angularViMocks.get('./my-other-service') ?? __angularViActualMod2; Requirements:
Alternatives consideredCurrently we have no choice, but stay with slow and inefficient I've implemented deep-automocking infrastructure for Reacted by HerrDerb, gcoadour, Arnaud Mouronval, TatyanaKonina, Pavel Biryuchev, Alexander, Alex Inkin, Lyudmila Kovtun, Nezar Khamidekh, Sam Bulatov and 20 more Activity
MetadataMetadataAssigneesTypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |