"Fossies" - the Fresh Open Source Software Archive 
Member "angular-cli-15.2.4/tests/angular_devkit/core/json/schema/serializers/0.0.javascript_spec.ts" (16 Mar 2023, 1094 Bytes) of package /linux/www/angular-cli-15.2.4.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8
9 // tslint:disable:no-any
10 import { schema } from '@angular-devkit/core';
11
12 const { serializers } = schema;
13
14
15 export function works(registry: schema.JsonSchemaRegistry, schema: any) {
16 const value = {
17 'firstName': 'Hans',
18 'lastName': 'Larsen',
19 'age': 30,
20 };
21
22 registry.addSchema('', schema);
23
24 const v = (new serializers.JavascriptSerializer()).serialize('', registry)(value);
25
26 expect(v.firstName).toBe('Hans');
27 expect(v.lastName).toBe('Larsen');
28 expect(v.age).toBe(30);
29
30 v.age = 10;
31 expect(v.age).toBe(10);
32
33 expect(() => v.age = -1).toThrow();
34 expect(() => v.age = 'hello').toThrow();
35 expect(() => v.age = []).toThrow();
36 expect(() => v.age = undefined).not.toThrow();
37
38 expect(() => v.firstName = 0).toThrow();
39 expect(() => v.firstName = []).toThrow();
40 // This should throw as the value is required.
41 expect(() => v.firstName = undefined).toThrow();
42 }