Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Jan 20, 2025
1 parent e44fc34 commit 4bc2c80
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('RendererFactory', () => {
rootDocstargetDOMNode = global.document.getElementById('root-docs');
(platformBrowserDynamic as any).mockImplementation(platformBrowserDynamicTesting);
vi.spyOn(console, 'log').mockImplementation(() => {});
globalThis.STORYBOOK_ANGULAR_OPTIONS = { experimentalZoneless: false };
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
Input,
Output,
Pipe,
input,
output,
} from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule } from '@angular/platform-browser-dynamic/testing';
Expand All @@ -26,7 +28,9 @@ import {

describe('getComponentInputsOutputs', () => {
it('should return empty if no I/O found', () => {
@Component({})
@Component({
standalone: false,
})
class FooComponent {}

expect(getComponentInputsOutputs(FooComponent)).toEqual({
Expand All @@ -47,11 +51,18 @@ describe('getComponentInputsOutputs', () => {
template: '',
inputs: ['inputInComponentMetadata'],
outputs: ['outputInComponentMetadata'],
standalone: false,
})
class FooComponent {
@Input()
public input: string;

public signalInput = input<string>();

public signalInputAliased = input<string>('signalInputAliased', {
alias: 'signalInputAliasedAlias',
});

@Input('inputPropertyName')
public inputWithBindingPropertyName: string;

Expand All @@ -60,6 +71,8 @@ describe('getComponentInputsOutputs', () => {

@Output('outputPropertyName')
public outputWithBindingPropertyName = new EventEmitter<Event>();

public signalOutput = output<string>();
}

const fooComponentFactory = resolveComponentFactory(FooComponent);
Expand All @@ -79,7 +92,9 @@ describe('getComponentInputsOutputs', () => {
],
});

expect(sortByPropName(inputs)).toEqual(sortByPropName(fooComponentFactory.inputs));
expect(sortByPropName(inputs)).toEqual(
sortByPropName(fooComponentFactory.inputs.map(({ isSignal, ...rest }) => rest))
);
expect(sortByPropName(outputs)).toEqual(sortByPropName(fooComponentFactory.outputs));
});

Expand All @@ -88,6 +103,7 @@ describe('getComponentInputsOutputs', () => {
template: '',
inputs: ['input', 'inputWithBindingPropertyName'],
outputs: ['outputWithBindingPropertyName'],
standalone: false,
})
class FooComponent {
@Input()
Expand All @@ -107,13 +123,16 @@ describe('getComponentInputsOutputs', () => {

const { inputs, outputs } = getComponentInputsOutputs(FooComponent);

expect(sortByPropName(inputs)).toEqual(sortByPropName(fooComponentFactory.inputs));
expect(sortByPropName(inputs)).toEqual(
sortByPropName(fooComponentFactory.inputs.map(({ isSignal, ...rest }) => rest))
);
expect(sortByPropName(outputs)).toEqual(sortByPropName(fooComponentFactory.outputs));
});

it('should return I/O in the presence of multiple decorators', () => {
@Component({
template: '',
standalone: false,
})
class FooComponent {
@Input()
Expand All @@ -137,13 +156,16 @@ describe('getComponentInputsOutputs', () => {
outputs: [],
});

expect(sortByPropName(inputs)).toEqual(sortByPropName(fooComponentFactory.inputs));
expect(sortByPropName(inputs)).toEqual(
sortByPropName(fooComponentFactory.inputs.map(({ isSignal, ...rest }) => rest))
);
expect(sortByPropName(outputs)).toEqual(sortByPropName(fooComponentFactory.outputs));
});

it('should return I/O with extending classes', () => {
@Component({
template: '',
standalone: false,
})
class BarComponent {
@Input()
Expand All @@ -155,6 +177,7 @@ describe('getComponentInputsOutputs', () => {

@Component({
template: '',
standalone: false,
})
class FooComponent extends BarComponent {
@Input()
Expand All @@ -177,7 +200,9 @@ describe('getComponentInputsOutputs', () => {
outputs: [],
});

expect(sortByPropName(inputs)).toEqual(sortByPropName(fooComponentFactory.inputs));
expect(sortByPropName(inputs)).toEqual(
sortByPropName(fooComponentFactory.inputs.map(({ isSignal, ...rest }) => rest))
);
expect(sortByPropName(outputs)).toEqual(sortByPropName(fooComponentFactory.outputs));
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ import { PropertyExtractor } from './PropertyExtractor';
const TEST_TOKEN = new InjectionToken('testToken');
const TestTokenProvider = { provide: TEST_TOKEN, useValue: 123 };
const TestService = Injectable()(class {});
const TestComponent1 = Component({})(class {});
const TestComponent2 = Component({})(class {});
const StandaloneTestComponent = Component({ standalone: true })(class {});
const StandaloneTestDirective = Directive({ standalone: true })(class {});
const MixedTestComponent1 = Component({ standalone: true })(
class extends StandaloneTestComponent {}
);
const MixedTestComponent2 = Component({})(class extends MixedTestComponent1 {});
const MixedTestComponent3 = Component({ standalone: true })(class extends MixedTestComponent2 {});
const TestComponent1 = Component({ standalone: false })(class {});
const TestComponent2 = Component({ standalone: false })(class {});
const StandaloneTestComponent = Component({})(class {});
const StandaloneTestDirective = Directive({})(class {});
const MixedTestComponent1 = Component({})(class extends StandaloneTestComponent {});
const MixedTestComponent2 = Component({ standalone: false })(class extends MixedTestComponent1 {});
const MixedTestComponent3 = Component({})(class extends MixedTestComponent2 {});
const TestModuleWithDeclarations = NgModule({ declarations: [TestComponent1] })(class {});
const TestModuleWithImportsAndProviders = NgModule({
imports: [TestModuleWithDeclarations],
Expand Down

0 comments on commit 4bc2c80

Please sign in to comment.