|
1 |
| -import { Component, input, output } from '@angular/core'; |
2 |
| -import { render, screen, inputBinding, outputBinding } from '../src/public_api'; |
| 1 | +import { Component, input, output, inputBinding, outputBinding } from '@angular/core'; |
| 2 | +import { render, screen, aliasedInput } from '../src/public_api'; |
3 | 3 |
|
4 | 4 | describe('ATL Bindings API Support', () => {
|
5 | 5 | @Component({
|
@@ -38,4 +38,45 @@ describe('ATL Bindings API Support', () => {
|
38 | 38 |
|
39 | 39 | expect(clickHandler).toHaveBeenCalledWith('clicked: bound-value');
|
40 | 40 | });
|
| 41 | + |
| 42 | + it('should warn when mixing bindings with traditional inputs but still work', async () => { |
| 43 | + const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(); |
| 44 | + const clickHandler = jest.fn(); |
| 45 | + const bindingClickHandler = jest.fn(); |
| 46 | + |
| 47 | + await render(BindingsTestComponent, { |
| 48 | + bindings: [inputBinding('value', () => 'binding-value'), outputBinding('clicked', bindingClickHandler)], |
| 49 | + inputs: { |
| 50 | + ...aliasedInput('greet', 'traditional-greeting'), // This will be ignored due to bindings |
| 51 | + }, |
| 52 | + on: { |
| 53 | + clicked: clickHandler, // This should still work alongside bindings |
| 54 | + }, |
| 55 | + }); |
| 56 | + |
| 57 | + // Only binding should work for inputs |
| 58 | + expect(screen.getByTestId('value')).toHaveTextContent('binding-value'); |
| 59 | + expect(screen.getByTestId('greeting')).toHaveTextContent('hello'); // Default value, not traditional |
| 60 | + |
| 61 | + const button = screen.getByTestId('emit-button'); |
| 62 | + button.click(); |
| 63 | + |
| 64 | + // Both binding and traditional handlers should be called for outputs |
| 65 | + expect(bindingClickHandler).toHaveBeenCalledWith('clicked: binding-value'); |
| 66 | + expect(clickHandler).toHaveBeenCalledWith('clicked: binding-value'); |
| 67 | + |
| 68 | + // Should show warning about mixed usage for inputs |
| 69 | + expect(consoleSpy).toHaveBeenCalledWith( |
| 70 | + 'ATL: You specified both bindings and traditional inputs. ' + |
| 71 | + 'Angular does not allow mixing setInput() with inputBinding(). ' + |
| 72 | + 'Only bindings will be used for inputs. Use bindings for all inputs to avoid this warning.', |
| 73 | + ); |
| 74 | + |
| 75 | + expect(consoleSpy).toHaveBeenCalledWith( |
| 76 | + 'ATL: You specified both bindings and traditional output listeners. ' + |
| 77 | + 'Consider using outputBinding() for all outputs for consistency.', |
| 78 | + ); |
| 79 | + |
| 80 | + consoleSpy.mockRestore(); |
| 81 | + }); |
41 | 82 | });
|
0 commit comments