-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(component): clean up cdAware creator and simplify strategy (#…
- Loading branch information
Showing
29 changed files
with
562 additions
and
540 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
65 changes: 0 additions & 65 deletions
65
modules/component/spec/core/cd-aware/get-change-detection-handling.spec.ts
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
modules/component/spec/core/cd-aware/render_creator.spec.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { createRender } from '../../../src/core/cd-aware'; | ||
import { | ||
manualInstanceNgZone, | ||
MockChangeDetectorRef, | ||
manualInstanceNoopNgZone, | ||
} from '../../fixtures/fixtures'; | ||
|
||
describe('renderCreator', () => { | ||
it('should create', () => { | ||
const render = createRender({ | ||
ngZone: manualInstanceNgZone, | ||
cdRef: new MockChangeDetectorRef(), | ||
}); | ||
expect(render).toBeDefined(); | ||
}); | ||
|
||
it('should call markForCheck', () => { | ||
const cdRef = new MockChangeDetectorRef(); | ||
const render = createRender({ ngZone: manualInstanceNgZone, cdRef }); | ||
render(); | ||
expect(cdRef.detectChanges).toHaveBeenCalledTimes(0); | ||
expect(cdRef.markForCheck).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call detectChanges', () => { | ||
const cdRef = new MockChangeDetectorRef(); | ||
const render = createRender({ ngZone: manualInstanceNoopNgZone, cdRef }); | ||
render(); | ||
expect(cdRef.detectChanges).toHaveBeenCalledTimes(1); | ||
expect(cdRef.markForCheck).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
48 changes: 0 additions & 48 deletions
48
modules/component/spec/core/projections/toObservableValue.spec.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { isNgZone } from '../../../src/core/utils'; | ||
import { | ||
manualInstanceNgZone, | ||
manualInstanceNoopNgZone, | ||
} from '../../fixtures/fixtures'; | ||
|
||
describe('envZonePatched', () => { | ||
it('should return true if `zone.js` did patch the global API', () => { | ||
expect(isNgZone(manualInstanceNgZone)).toBe(true); | ||
}); | ||
|
||
it('should return false if `zone.js` did not patch the global API', () => { | ||
expect(isNgZone(manualInstanceNoopNgZone)).toBe(false); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import createSpy = jasmine.createSpy; | ||
import { ChangeDetectorRef } from '@angular/core'; | ||
import { MockNgZone } from './mock-ng-zone'; | ||
import { MockNoopNgZone } from './mock-noop-ng-zone'; | ||
|
||
/** | ||
* this is not exposed as NgZone should never be exposed to get miss matched with the real one | ||
*/ | ||
class NgZone extends MockNgZone {} | ||
|
||
/** | ||
* this is not exposed as NgZone should never be exposed to get miss matched with the real one | ||
*/ | ||
class NoopNgZone extends MockNoopNgZone {} | ||
|
||
export const manualInstanceNgZone = new NgZone({ | ||
enableLongStackTrace: false, | ||
shouldCoalesceEventChangeDetection: false, | ||
}); | ||
export const manualInstanceNoopNgZone = new NoopNgZone({ | ||
enableLongStackTrace: false, | ||
shouldCoalesceEventChangeDetection: false, | ||
}); | ||
|
||
export class MockChangeDetectorRef { | ||
markForCheck = createSpy('markForCheck'); | ||
detectChanges = createSpy('detectChanges'); | ||
checkNoChanges = createSpy('checkNoChanges'); | ||
detach = createSpy('detach'); | ||
reattach = createSpy('reattach'); | ||
} | ||
|
||
export const mockPromise = { | ||
then: () => {}, | ||
}; | ||
|
||
export function getMockOptimizedStrategyConfig() { | ||
return { | ||
component: {}, | ||
cdRef: (new MockChangeDetectorRef() as any) as ChangeDetectorRef, | ||
}; | ||
} | ||
|
||
export function getMockNoopStrategyConfig() { | ||
return { | ||
component: {}, | ||
cdRef: (new MockChangeDetectorRef() as any) as ChangeDetectorRef, | ||
}; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { EventEmitter } from '@angular/core'; | ||
|
||
export class MockEventEmitter<T> extends EventEmitter<T> { | ||
next(value: any) {} | ||
error(error: any) {} | ||
complete() {} | ||
emit() {} | ||
} |
Oops, something went wrong.