-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ngMocks.faster): support of angular 14.2.0 #3466
- Loading branch information
Showing
7 changed files
with
78 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 50 additions & 12 deletions
62
libs/ng-mocks/src/lib/mock-helper/mock-helper.faster-install.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,94 @@ | ||
import { TestBed, TestBedStatic, TestModuleMetadata } from '@angular/core/testing'; | ||
import { getTestBed, TestBed, TestBedStatic, TestModuleMetadata } from '@angular/core/testing'; | ||
|
||
import coreDefineProperty from '../common/core.define-property'; | ||
import ngMocksUniverse from '../common/ng-mocks-universe'; | ||
|
||
const hooks: { | ||
after: Array<(original: TestBedStatic['resetTestingModule']) => TestBedStatic['resetTestingModule']>; | ||
before: Array<(original: TestBedStatic['configureTestingModule']) => TestBedStatic['configureTestingModule']>; | ||
after: Array< | ||
(original: TestBedStatic['resetTestingModule'], instance: TestBedStatic) => TestBedStatic['resetTestingModule'] | ||
>; | ||
before: Array< | ||
( | ||
original: TestBedStatic['configureTestingModule'], | ||
instance: TestBedStatic, | ||
) => TestBedStatic['configureTestingModule'] | ||
>; | ||
} = ngMocksUniverse.global.get('faster-hooks') || { | ||
after: [], | ||
before: [], | ||
}; | ||
ngMocksUniverse.global.set('faster-hooks', hooks); | ||
|
||
const configureTestingModule = | ||
(original: TestBedStatic['configureTestingModule']): TestBedStatic['configureTestingModule'] => | ||
( | ||
original: TestBedStatic['configureTestingModule'], | ||
instance: TestBedStatic, | ||
): TestBedStatic['configureTestingModule'] => | ||
(moduleDef: TestModuleMetadata) => { | ||
if ((TestBed as any).ngMocksFasterLock) { | ||
return original.call(instance, moduleDef); | ||
} | ||
|
||
ngMocksUniverse.global.set('bullet:customized', true); | ||
|
||
let final = original; | ||
for (const callback of hooks.before) { | ||
final = callback(final); | ||
final = callback(final, instance); | ||
} | ||
|
||
return final.call(TestBed, moduleDef); | ||
try { | ||
coreDefineProperty(TestBed, 'ngMocksFasterLock', true); | ||
|
||
return final.call(instance, moduleDef); | ||
} finally { | ||
coreDefineProperty(TestBed, 'ngMocksFasterLock', undefined); | ||
} | ||
}; | ||
|
||
const resetTestingModule = | ||
(original: TestBedStatic['resetTestingModule']): TestBedStatic['resetTestingModule'] => | ||
(original: TestBedStatic['resetTestingModule'], instance: TestBedStatic): TestBedStatic['resetTestingModule'] => | ||
() => { | ||
if ((TestBed as any).ngMocksFasterLock) { | ||
return original.call(instance); | ||
} | ||
|
||
if (ngMocksUniverse.global.has('bullet')) { | ||
if (ngMocksUniverse.global.has('bullet:customized')) { | ||
ngMocksUniverse.global.set('bullet:reset', true); | ||
} | ||
|
||
return TestBed; | ||
return instance; | ||
} | ||
ngMocksUniverse.global.delete('bullet:customized'); | ||
ngMocksUniverse.global.delete('bullet:reset'); | ||
|
||
let final = original; | ||
for (const callback of hooks.after) { | ||
final = callback(final); | ||
final = callback(final, instance); | ||
} | ||
|
||
return final.call(TestBed); | ||
try { | ||
coreDefineProperty(TestBed, 'ngMocksFasterLock', true); | ||
|
||
return final.call(instance); | ||
} finally { | ||
coreDefineProperty(TestBed, 'ngMocksFasterLock', undefined); | ||
} | ||
}; | ||
|
||
export default () => { | ||
if (!(TestBed as any).ngMocksFasterInstalled) { | ||
TestBed.configureTestingModule = configureTestingModule(TestBed.configureTestingModule); | ||
TestBed.resetTestingModule = resetTestingModule(TestBed.resetTestingModule); | ||
TestBed.configureTestingModule = configureTestingModule(TestBed.configureTestingModule as never, TestBed as never); | ||
TestBed.resetTestingModule = resetTestingModule(TestBed.resetTestingModule as never, TestBed as never); | ||
coreDefineProperty(TestBed, 'ngMocksFasterInstalled', true); | ||
} | ||
|
||
const testBed = getTestBed(); | ||
if (!(testBed as any).ngMocksFasterInstalled) { | ||
testBed.configureTestingModule = configureTestingModule(testBed.configureTestingModule as never, testBed as never); | ||
testBed.resetTestingModule = resetTestingModule(testBed.resetTestingModule as never, testBed as never); | ||
coreDefineProperty(testBed, 'ngMocksFasterInstalled', true); | ||
} | ||
|
||
return hooks; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters