-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathhtml-selector_spec.ts
67 lines (57 loc) · 2.27 KB
/
html-selector_spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { map } from 'rxjs/operators';
import { formatValidator } from './format-validator';
import { htmlSelectorFormat } from './html-selector';
describe('Schematics HTML selector format', () => {
it('accepts correct selectors', done => {
const data = { selector: 'my-selector' };
const dataSchema = {
properties: { selector: { type: 'string', format: 'html-selector' } },
};
formatValidator(data, dataSchema, [htmlSelectorFormat])
.pipe(map(result => expect(result.success).toBe(true)))
.toPromise().then(done, done.fail);
});
it('rejects selectors starting with invalid characters', done => {
const data = { selector: 'my-selector$' };
const dataSchema = {
properties: { selector: { type: 'string', format: 'html-selector' } },
};
formatValidator(data, dataSchema, [htmlSelectorFormat])
.pipe(map(result => expect(result.success).toBe(false)))
.toPromise().then(done, done.fail);
});
it('rejects selectors starting with number', done => {
const data = { selector: '1selector' };
const dataSchema = {
properties: { selector: { type: 'string', format: 'html-selector' } },
};
formatValidator(data, dataSchema, [htmlSelectorFormat])
.pipe(map(result => expect(result.success).toBe(false)))
.toPromise().then(done, done.fail);
});
it('accepts selectors with non-letter after dash', done => {
const data = { selector: 'my-1selector' };
const dataSchema = {
properties: { selector: { type: 'string', format: 'html-selector' } },
};
formatValidator(data, dataSchema, [htmlSelectorFormat])
.pipe(map(result => expect(result.success).toBe(true)))
.toPromise().then(done, done.fail);
});
it('accepts selectors with unicode', done => {
const data = { selector: 'app-root😀' };
const dataSchema = {
properties: { selector: { type: 'string', format: 'html-selector' } },
};
formatValidator(data, dataSchema, [htmlSelectorFormat])
.pipe(map(result => expect(result.success).toBe(true)))
.toPromise().then(done, done.fail);
});
});