2016-08-23 00:17:23 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
2020-05-19 19:08:49 +00:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2016-08-23 00:17:23 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 15:23:15 +00:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2016-08-23 00:17:23 +00:00
|
|
|
*/
|
|
|
|
|
|
2016-08-31 01:07:40 +00:00
|
|
|
/**
|
|
|
|
|
* @module
|
|
|
|
|
* @description
|
|
|
|
|
* Entry point for all public APIs of the core/testing package.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-08-23 00:17:23 +00:00
|
|
|
export * from './async';
|
2024-01-18 22:09:19 +00:00
|
|
|
export {ComponentFixture} from './component_fixture';
|
2024-03-28 17:20:55 +00:00
|
|
|
export {
|
|
|
|
|
resetFakeAsyncZone,
|
|
|
|
|
discardPeriodicTasks,
|
|
|
|
|
fakeAsync,
|
|
|
|
|
flush,
|
|
|
|
|
flushMicrotasks,
|
|
|
|
|
tick,
|
|
|
|
|
} from './fake_async';
|
2022-07-01 06:33:06 +00:00
|
|
|
export {
|
|
|
|
|
TestBed,
|
|
|
|
|
getTestBed,
|
|
|
|
|
TestBedStatic,
|
|
|
|
|
inject,
|
|
|
|
|
InjectSetupWrapper,
|
|
|
|
|
withModule,
|
feat(core): support bindings in TestBed (#62040)
Adds support for passing in `Binding` objects into `TestBed.createComponent`. This makes it easier to test components by avoiding the need to create a wrapper component. Furthermore, it keeps the behavior consistent between tests and the actual app. For example, given a custom checkbox that looks like this:
```typescript
@Component({
selector: 'my-checkbox',
template: '...',
host: {'[class.checked]': 'isChecked()'}
})
export class MyCheckbox {
isChecked = input(false);
}
```
A test for the `isChecked` input would look something like this:
```typescript
it('should toggle the checked class', () => {
@Component({
imports: [MyCheckbox],
template: '<my-checkbox [isChecked]="isChecked"/>',
})
class Wrapper {
isChecked = false;
}
const fixture = TestBed.createComponent(Wrapper);
const checkbox = fixture.nativeElement.querySelector('my-checkbox');
fixture.detectChanges();
expect(checkbox.classList).not.toContain('checked');
fixture.componentInstance.isChecked = true;
fixture.detectChanges();
expect(checkbox.classList).toContain('checked');
});
```
Whereas with the new API, the test would look like this:
```typescript
it('should toggle the checked class', () => {
const isChecked = signal(false);
const fixture = TestBed.createComponent(MyCheckbox, {
bindings: [inputBinding('isChecked', isChecked)]
});
const checkbox = fixture.nativeElement.querySelector('my-checkbox');
fixture.detectChanges();
expect(checkbox.classList).not.toContain('checked');
isChecked.set(true);
fixture.detectChanges();
expect(checkbox.classList).toContain('checked');
});
```
PR Close #62040
2025-06-14 05:00:38 +00:00
|
|
|
TestComponentOptions,
|
2022-07-01 06:33:06 +00:00
|
|
|
} from './test_bed';
|
|
|
|
|
export {
|
|
|
|
|
TestComponentRenderer,
|
|
|
|
|
ComponentFixtureAutoDetect,
|
|
|
|
|
ComponentFixtureNoNgZone,
|
|
|
|
|
TestModuleMetadata,
|
|
|
|
|
TestEnvironmentOptions,
|
|
|
|
|
ModuleTeardownOptions,
|
|
|
|
|
} from './test_bed_common';
|
2016-08-23 00:17:23 +00:00
|
|
|
export * from './metadata_override';
|
2018-08-14 23:27:04 +00:00
|
|
|
export {MetadataOverrider as ɵMetadataOverrider} from './metadata_overrider';
|
2023-09-01 17:29:14 +00:00
|
|
|
export {
|
|
|
|
|
ɵDeferBlockBehavior as DeferBlockBehavior,
|
|
|
|
|
ɵDeferBlockState as DeferBlockState,
|
|
|
|
|
} from '../../src/core';
|
|
|
|
|
export {DeferBlockFixture} from './defer';
|