Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/src/metadata/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ export interface Component extends Directive {
*/
export const Component: ComponentDecorator = makeDecorator(
'Component',
(c: Component = {}) => ({changeDetection: ChangeDetectionStrategy.Eager, ...c}),
(c: Component = {}) => ({changeDetection: ChangeDetectionStrategy.OnPush, ...c}),
Directive,
undefined,
(type: Type<any>, meta: Component) => compileComponent(type, meta),
Expand Down
16 changes: 16 additions & 0 deletions packages/core/test/acceptance/change_detection_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
ViewChildren,
ViewContainerRef,
} from '../../src/core';
import {getComponentDef} from '../../src/render3/def_getters';
import {ComponentFixture, ComponentFixtureAutoDetect, TestBed} from '../../testing';

describe('change detection', () => {
Expand All @@ -56,6 +57,21 @@ describe('change detection', () => {
TestBed.inject(ApplicationRef);
}).not.toThrow();
});
it('defaults an unspecified changeDetection strategy to OnPush, matching the AOT compiler default', () => {
// The `@Component` decorator itself must default to OnPush, the same way the AOT
// compiler does (see `compileComponentFromMetadata` in
// packages/compiler/src/render3/view/compiler.ts). Before this fix, the JIT decorator
// in this file still defaulted to `ChangeDetectionStrategy.Eager`, so a component
// without an explicit `changeDetection` behaved differently under TestBed/JIT than in
// a production AOT build.
@Component({
selector: 'default-cd-comp',
template: '',
})
class DefaultCdComponent {}

expect(getComponentDef(DefaultCdComponent)!.onPush).toBe(true);
});
describe('embedded views', () => {
@Directive({
selector: '[viewManipulation]',
Expand Down