Skip to content

Commit f0d05d2

Browse files
committed
test(platform-server): add SSR integration test for null and normal input values
Add an Angular SSR integration test in platform-server verifying that null input values do not render string attributes like value=null during server-side rendering, while normal non-empty string values like value=hello are properly preserved. Fixes angular#69785
1 parent 223e402 commit f0d05d2

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

packages/platform-server/test/full_app_hydration_spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,30 @@ describe('platform-server full application hydration integration', () => {
211211
expect(ssrContents).not.toContain(extraChildNodes);
212212
expect(ssrContents).toContain('<app ngh="0"><div>Some content</div></app>');
213213
});
214+
215+
it('should serialize input values correctly for both null and normal non-empty values during SSR', async () => {
216+
@Component({
217+
selector: 'app',
218+
template: `
219+
<input id="input-null" [value]="nullValue" />
220+
<input id="input-normal" [value]="normalValue" />
221+
`,
222+
})
223+
class AppComponent {
224+
nullValue: string | null = null;
225+
normalValue = 'hello';
226+
}
227+
228+
const html = await ssr(AppComponent);
229+
const ssrContents = getAppContents(html);
230+
231+
// A `null` value should not be reflected as a `value` attribute at all.
232+
expect(ssrContents).toContain('<input id="input-null">');
233+
expect(ssrContents).not.toContain('value="null"');
234+
235+
// A normal, non-empty value should be reflected as-is.
236+
expect(ssrContents).toContain('<input id="input-normal" value="hello">');
237+
});
214238
});
215239

216240
describe('hydration', () => {

0 commit comments

Comments
 (0)