本文整理汇总了TypeScript中@angular/core/testing/src/testing_internal.describe函数的典型用法代码示例。如果您正苦于以下问题:TypeScript describe函数的具体用法?TypeScript describe怎么用?TypeScript describe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了describe函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('UrlResolver', () => {
let resolver = new UrlResolver();
describe('absolute base url', () => {
it('should add a relative path to the base url', () => {
expect(resolver.resolve('http://www.foo.com', 'bar')).toEqual('http://www.foo.com/bar');
expect(resolver.resolve('http://www.foo.com/', 'bar')).toEqual('http://www.foo.com/bar');
expect(resolver.resolve('http://www.foo.com', './bar')).toEqual('http://www.foo.com/bar');
expect(resolver.resolve('http://www.foo.com/', './bar')).toEqual('http://www.foo.com/bar');
});
it('should replace the base path', () => {
expect(resolver.resolve('http://www.foo.com/baz', 'bar')).toEqual('http://www.foo.com/bar');
expect(resolver.resolve('http://www.foo.com/baz', './bar'))
.toEqual('http://www.foo.com/bar');
});
it('should append to the base path', () => {
expect(resolver.resolve('http://www.foo.com/baz/', 'bar'))
.toEqual('http://www.foo.com/baz/bar');
expect(resolver.resolve('http://www.foo.com/baz/', './bar'))
.toEqual('http://www.foo.com/baz/bar');
});
it('should support ".." in the path', () => {
expect(resolver.resolve('http://www.foo.com/baz/', '../bar'))
.toEqual('http://www.foo.com/bar');
expect(resolver.resolve('http://www.foo.com/1/2/3/', '../../bar'))
.toEqual('http://www.foo.com/1/bar');
expect(resolver.resolve('http://www.foo.com/1/2/3/', '../biz/bar'))
.toEqual('http://www.foo.com/1/2/biz/bar');
expect(resolver.resolve('http://www.foo.com/1/2/baz', '../../bar'))
.toEqual('http://www.foo.com/bar');
});
it('should ignore the base path when the url has a scheme', () => {
expect(resolver.resolve('http://www.foo.com', 'http://www.bar.com'))
.toEqual('http://www.bar.com');
});
it('should support absolute urls', () => {
expect(resolver.resolve('http://www.foo.com', '/bar')).toEqual('http://www.foo.com/bar');
expect(resolver.resolve('http://www.foo.com/', '/bar')).toEqual('http://www.foo.com/bar');
expect(resolver.resolve('http://www.foo.com/baz', '/bar'))
.toEqual('http://www.foo.com/bar');
expect(resolver.resolve('http://www.foo.com/baz/', '/bar'))
.toEqual('http://www.foo.com/bar');
});
});
describe('relative base url', () => {
it('should add a relative path to the base url', () => {
expect(resolver.resolve('foo/', './bar')).toEqual('foo/bar');
expect(resolver.resolve('foo/baz', './bar')).toEqual('foo/bar');
expect(resolver.resolve('foo/baz', 'bar')).toEqual('foo/bar');
});
it('should support ".." in the path', () => {
expect(resolver.resolve('foo/baz', '../bar')).toEqual('bar');
expect(resolver.resolve('foo/baz', '../biz/bar')).toEqual('biz/bar');
});
it('should support absolute urls', () => {
expect(resolver.resolve('foo/baz', '/bar')).toEqual('/bar');
expect(resolver.resolve('foo/baz/', '/bar')).toEqual('/bar');
});
it('should not resolve urls against the baseUrl when the url contains a scheme', () => {
resolver = new UrlResolver('my_packages_dir');
expect(resolver.resolve('base/', 'package:file')).toEqual('my_packages_dir/file');
expect(resolver.resolve('base/', 'http:super_file')).toEqual('http:super_file');
expect(resolver.resolve('base/', './mega_file')).toEqual('base/mega_file');
});
});
describe('packages', () => {
it('should resolve a url based on the application package', () => {
resolver = new UrlResolver('my_packages_dir');
expect(resolver.resolve(null !, 'package:some/dir/file.txt'))
.toEqual('my_packages_dir/some/dir/file.txt');
expect(resolver.resolve(null !, 'some/dir/file.txt')).toEqual('some/dir/file.txt');
});
it('should contain a default value of "/" when nothing is provided',
inject([UrlResolver], (resolver: UrlResolver) => {
expect(resolver.resolve(null !, 'package:file')).toEqual('/file');
}));
it('should resolve a package value when present within the baseurl', () => {
resolver = new UrlResolver('/my_special_dir');
expect(resolver.resolve('package:some_dir/', 'matias.html'))
.toEqual('/my_special_dir/some_dir/matias.html');
});
});
describe('corner and error cases', () => {
it('should encode URLs before resolving',
() => {
expect(resolver.resolve('foo/baz', `<p #p>Hello
//.........这里部分代码省略.........
示例2: describe
describe('disable() & enable()', () => {
let a: FormArray;
let c: FormControl;
let c2: FormControl;
beforeEach(() => {
c = new FormControl(null);
c2 = new FormControl(null);
a = new FormArray([c, c2]);
});
it('should mark the array as disabled', () => {
expect(a.disabled).toBe(false);
expect(a.valid).toBe(true);
a.disable();
expect(a.disabled).toBe(true);
expect(a.valid).toBe(false);
a.enable();
expect(a.disabled).toBe(false);
expect(a.valid).toBe(true);
});
it('should set the array status as disabled', () => {
expect(a.status).toBe('VALID');
a.disable();
expect(a.status).toBe('DISABLED');
a.enable();
expect(a.status).toBe('VALID');
});
it('should mark children of the array as disabled', () => {
expect(c.disabled).toBe(false);
expect(c2.disabled).toBe(false);
a.disable();
expect(c.disabled).toBe(true);
expect(c2.disabled).toBe(true);
a.enable();
expect(c.disabled).toBe(false);
expect(c2.disabled).toBe(false);
});
it('should ignore disabled controls in validation', () => {
const g = new FormGroup({
nested: new FormArray([new FormControl(null, Validators.required)]),
two: new FormControl('two')
});
expect(g.valid).toBe(false);
g.get('nested') !.disable();
expect(g.valid).toBe(true);
g.get('nested') !.enable();
expect(g.valid).toBe(false);
});
it('should ignore disabled controls when serializing value', () => {
const g = new FormGroup(
{nested: new FormArray([new FormControl('one')]), two: new FormControl('two')});
expect(g.value).toEqual({'nested': ['one'], 'two': 'two'});
g.get('nested') !.disable();
expect(g.value).toEqual({'two': 'two'});
g.get('nested') !.enable();
expect(g.value).toEqual({'nested': ['one'], 'two': 'two'});
});
it('should ignore disabled controls when determining dirtiness', () => {
const g = new FormGroup({nested: a, two: new FormControl('two')});
g.get(['nested', 0]) !.markAsDirty();
expect(g.dirty).toBe(true);
g.get('nested') !.disable();
expect(g.get('nested') !.dirty).toBe(true);
expect(g.dirty).toEqual(false);
g.get('nested') !.enable();
expect(g.dirty).toEqual(true);
});
it('should ignore disabled controls when determining touched state', () => {
const g = new FormGroup({nested: a, two: new FormControl('two')});
g.get(['nested', 0]) !.markAsTouched();
expect(g.touched).toBe(true);
g.get('nested') !.disable();
expect(g.get('nested') !.touched).toBe(true);
expect(g.touched).toEqual(false);
g.get('nested') !.enable();
expect(g.touched).toEqual(true);
});
it('should keep empty, disabled arrays disabled when updating validity', () => {
//.........这里部分代码省略.........
示例3: describe
describe('console reporter', () => {
let reporter: ConsoleReporter;
let log: string[];
function createReporter(
{columnWidth = null, sampleId = null, descriptions = null, metrics = null}: {
columnWidth?: number | null,
sampleId?: string | null,
descriptions?: {[key: string]: any}[] | null,
metrics?: {[key: string]: any} | null
}) {
log = [];
if (!descriptions) {
descriptions = [];
}
if (sampleId == null) {
sampleId = 'null';
}
const providers: StaticProvider[] = [
ConsoleReporter.PROVIDERS, {
provide: SampleDescription,
useValue: new SampleDescription(sampleId, descriptions, metrics !)
},
{provide: ConsoleReporter.PRINT, useValue: (line: string) => log.push(line)}
];
if (columnWidth != null) {
providers.push({provide: ConsoleReporter.COLUMN_WIDTH, useValue: columnWidth});
}
reporter = Injector.create(providers).get(ConsoleReporter);
}
it('should print the sample id, description and table header', () => {
createReporter({
columnWidth: 8,
sampleId: 'someSample',
descriptions: [{'a': 1, 'b': 2}],
metrics: {'m1': 'some desc', 'm2': 'some other desc'}
});
expect(log).toEqual([
'BENCHMARK someSample',
'Description:',
'- a: 1',
'- b: 2',
'Metrics:',
'- m1: some desc',
'- m2: some other desc',
'',
' m1 | m2',
'-------- | --------',
]);
});
it('should print a table row', () => {
createReporter({columnWidth: 8, metrics: {'a': '', 'b': ''}});
log = [];
reporter.reportMeasureValues(mv(0, 0, {'a': 1.23, 'b': 2}));
expect(log).toEqual([' 1.23 | 2.00']);
});
it('should print the table footer and stats when there is a valid sample', () => {
createReporter({columnWidth: 8, metrics: {'a': '', 'b': ''}});
log = [];
reporter.reportSample([], [mv(0, 0, {'a': 3, 'b': 6}), mv(1, 1, {'a': 5, 'b': 9})]);
expect(log).toEqual(['======== | ========', '4.00+-25% | 7.50+-20%']);
});
it('should print the coefficient of variation only when it is meaningful', () => {
createReporter({columnWidth: 8, metrics: {'a': '', 'b': ''}});
log = [];
reporter.reportSample([], [mv(0, 0, {'a': 3, 'b': 0}), mv(1, 1, {'a': 5, 'b': 0})]);
expect(log).toEqual(['======== | ========', '4.00+-25% | 0.00']);
});
});
示例4: main
export function main() {
/**
* Tests the PostMessageBus
*/
describe('MessageBus', () => {
let bus: MessageBus;
beforeEach(() => { bus = createConnectedMessageBus(); });
it('should pass messages in the same channel from sink to source',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const CHANNEL = 'CHANNEL 1';
const MESSAGE = 'Test message';
bus.initChannel(CHANNEL, false);
const fromEmitter = bus.from(CHANNEL);
fromEmitter.subscribe({
next: (message: any) => {
expect(message).toEqual(MESSAGE);
async.done();
}
});
const toEmitter = bus.to(CHANNEL);
toEmitter.emit(MESSAGE);
}));
it('should broadcast', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const CHANNEL = 'CHANNEL 1';
const MESSAGE = 'TESTING';
const NUM_LISTENERS = 2;
bus.initChannel(CHANNEL, false);
let callCount = 0;
const emitHandler = (message: any) => {
expect(message).toEqual(MESSAGE);
callCount++;
if (callCount == NUM_LISTENERS) {
async.done();
}
};
for (let i = 0; i < NUM_LISTENERS; i++) {
const emitter = bus.from(CHANNEL);
emitter.subscribe({next: emitHandler});
}
const toEmitter = bus.to(CHANNEL);
toEmitter.emit(MESSAGE);
}));
it('should keep channels independent',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const CHANNEL_ONE = 'CHANNEL 1';
const CHANNEL_TWO = 'CHANNEL 2';
const MESSAGE_ONE = 'This is a message on CHANNEL 1';
const MESSAGE_TWO = 'This is a message on CHANNEL 2';
let callCount = 0;
bus.initChannel(CHANNEL_ONE, false);
bus.initChannel(CHANNEL_TWO, false);
const firstFromEmitter = bus.from(CHANNEL_ONE);
firstFromEmitter.subscribe({
next: (message: any) => {
expect(message).toEqual(MESSAGE_ONE);
callCount++;
if (callCount == 2) {
async.done();
}
}
});
const secondFromEmitter = bus.from(CHANNEL_TWO);
secondFromEmitter.subscribe({
next: (message: any) => {
expect(message).toEqual(MESSAGE_TWO);
callCount++;
if (callCount == 2) {
async.done();
}
}
});
const firstToEmitter = bus.to(CHANNEL_ONE);
firstToEmitter.emit(MESSAGE_ONE);
const secondToEmitter = bus.to(CHANNEL_TWO);
secondToEmitter.emit(MESSAGE_TWO);
}));
});
describe('PostMessageBusSink', () => {
let bus: MessageBus;
const CHANNEL = 'Test Channel';
function setup(runInZone: boolean, zone: NgZone) {
bus.attachToZone(zone);
bus.initChannel(CHANNEL, runInZone);
}
/**
* Flushes pending messages and then runs the given function.
//.........这里部分代码省略.........
示例5: describe
describe('readPerfLog (common)', () => {
it('should execute a dummy script before reading them',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
// TODO(tbosch): This seems to be a bug in ChromeDriver:
// Sometimes it does not report the newest events of the performance log
// to the WebDriver client unless a script is executed...
createExtension([]).readPerfLog().then((_) => {
expect(log).toEqual([['executeScript', '1+1'], ['logs', 'performance']]);
async.done();
});
}));
['Rasterize', 'CompositeLayers'].forEach((recordType) => {
it(`should report ${recordType} as "render"`,
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
createExtension(
[
chromeTimelineEvents.start(recordType, 1234),
chromeTimelineEvents.end(recordType, 2345)
], )
.readPerfLog()
.then((events) => {
expect(events).toEqual([
normEvents.start('render', 1.234),
normEvents.end('render', 2.345),
]);
async.done();
});
}));
});
describe('frame metrics', () => {
it('should report ImplThreadRenderingStats as frame event',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
createExtension([benchmarkEvents.instant(
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
{'data': {'frame_count': 1}})])
.readPerfLog()
.then((events) => {
expect(events).toEqual([
normEvents.instant('frame', 1.1),
]);
async.done();
});
}));
it('should not report ImplThreadRenderingStats with zero frames',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
createExtension([benchmarkEvents.instant(
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
{'data': {'frame_count': 0}})])
.readPerfLog()
.then((events) => {
expect(events).toEqual([]);
async.done();
});
}));
it('should throw when ImplThreadRenderingStats contains more than one frame',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
createExtension([benchmarkEvents.instant(
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
{'data': {'frame_count': 2}})])
.readPerfLog()
.catch((err): any => {
expect(() => {
throw err;
}).toThrowError('multi-frame render stats not supported');
async.done();
});
}));
});
it('should report begin timestamps',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
createExtension([blinkEvents.create('S', 'someName', 1000)])
.readPerfLog()
.then((events) => {
expect(events).toEqual([normEvents.markStart('someName', 1.0)]);
async.done();
});
}));
it('should report end timestamps',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
createExtension([blinkEvents.create('F', 'someName', 1000)])
.readPerfLog()
.then((events) => {
expect(events).toEqual([normEvents.markEnd('someName', 1.0)]);
async.done();
});
}));
it('should throw an error on buffer overflow',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
createExtension(
//.........这里部分代码省略.........
示例6: describe
describe('Validators', () => {
describe('required', () => {
it('should error on an empty string',
() => { expect(Validators.required(new FormControl(''))).toEqual({'required': true}); });
it('should error on null',
() => { expect(Validators.required(new FormControl(null))).toEqual({'required': true}); });
it('should not error on undefined', () => {
expect(Validators.required(new FormControl(undefined))).toEqual({'required': true});
});
it('should not error on a non-empty string',
() => { expect(Validators.required(new FormControl('not empty'))).toBeNull(); });
it('should accept zero as valid',
() => { expect(Validators.required(new FormControl(0))).toBeNull(); });
it('should error on an empty array',
() => expect(Validators.required(new FormControl([]))).toEqual({'required': true}));
it('should not error on a non-empty array',
() => expect(Validators.required(new FormControl([1, 2]))).toBeNull());
});
describe('requiredTrue', () => {
it('should error on false',
() => expect(Validators.requiredTrue(new FormControl(false))).toEqual({'required': true}));
it('should not error on true',
() => expect(Validators.requiredTrue(new FormControl(true))).toBeNull());
});
describe('email', () => {
it('should error on invalid email',
() => expect(Validators.email(new FormControl('some text'))).toEqual({'email': true}));
it('should not error on valid email',
() => expect(Validators.email(new FormControl('test@gmail.com'))).toBeNull());
});
describe('minLength', () => {
it('should not error on an empty string',
() => { expect(Validators.minLength(2)(new FormControl(''))).toBeNull(); });
it('should not error on null',
() => { expect(Validators.minLength(2)(new FormControl(null))).toBeNull(); });
it('should not error on undefined',
() => { expect(Validators.minLength(2)(new FormControl(undefined))).toBeNull(); });
it('should not error on valid strings',
() => { expect(Validators.minLength(2)(new FormControl('aa'))).toBeNull(); });
it('should error on short strings', () => {
expect(Validators.minLength(2)(new FormControl('a'))).toEqual({
'minlength': {'requiredLength': 2, 'actualLength': 1}
});
});
it('should not error when FormArray has valid length', () => {
const fa = new FormArray([new FormControl(''), new FormControl('')]);
expect(Validators.minLength(2)(fa)).toBeNull();
});
it('should error when FormArray has invalid length', () => {
const fa = new FormArray([new FormControl('')]);
expect(Validators.minLength(2)(fa)).toEqual({
'minlength': {'requiredLength': 2, 'actualLength': 1}
});
});
});
describe('maxLength', () => {
it('should not error on an empty string',
() => { expect(Validators.maxLength(2)(new FormControl(''))).toBeNull(); });
it('should not error on null',
() => { expect(Validators.maxLength(2)(new FormControl(null))).toBeNull(); });
it('should not error on undefined',
() => { expect(Validators.maxLength(2)(new FormControl(undefined))).toBeNull(); });
it('should not error on valid strings',
() => { expect(Validators.maxLength(2)(new FormControl('aa'))).toBeNull(); });
it('should error on long strings', () => {
expect(Validators.maxLength(2)(new FormControl('aaa'))).toEqual({
'maxlength': {'requiredLength': 2, 'actualLength': 3}
});
});
it('should not error when FormArray has valid length', () => {
const fa = new FormArray([new FormControl(''), new FormControl('')]);
expect(Validators.maxLength(2)(fa)).toBeNull();
});
it('should error when FormArray has invalid length', () => {
const fa = new FormArray([new FormControl(''), new FormControl('')]);
expect(Validators.maxLength(1)(fa)).toEqual({
//.........这里部分代码省略.........
示例7: main
export function main() {
describe('MockResourceLoader', () => {
let resourceLoader: MockResourceLoader;
beforeEach(() => { resourceLoader = new MockResourceLoader(); });
function expectResponse(
request: Promise<string>, url: string, response: string, done: () => void = null) {
function onResponse(text: string): string {
if (response === null) {
throw `Unexpected response ${url} -> ${text}`;
} else {
expect(text).toEqual(response);
if (done != null) done();
}
return text;
}
function onError(error: string): string {
if (response !== null) {
throw `Unexpected error ${url}`;
} else {
expect(error).toEqual(`Failed to load ${url}`);
if (done != null) done();
}
return error;
}
request.then(onResponse, onError);
}
it('should return a response from the definitions',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const url = '/foo';
const response = 'bar';
resourceLoader.when(url, response);
expectResponse(resourceLoader.get(url), url, response, () => async.done());
resourceLoader.flush();
}));
it('should return an error from the definitions',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const url = '/foo';
const response: string = null;
resourceLoader.when(url, response);
expectResponse(resourceLoader.get(url), url, response, () => async.done());
resourceLoader.flush();
}));
it('should return a response from the expectations',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const url = '/foo';
const response = 'bar';
resourceLoader.expect(url, response);
expectResponse(resourceLoader.get(url), url, response, () => async.done());
resourceLoader.flush();
}));
it('should return an error from the expectations',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const url = '/foo';
const response: string = null;
resourceLoader.expect(url, response);
expectResponse(resourceLoader.get(url), url, response, () => async.done());
resourceLoader.flush();
}));
it('should not reuse expectations', () => {
const url = '/foo';
const response = 'bar';
resourceLoader.expect(url, response);
resourceLoader.get(url);
resourceLoader.get(url);
expect(() => { resourceLoader.flush(); }).toThrowError('Unexpected request /foo');
});
it('should return expectations before definitions',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
const url = '/foo';
resourceLoader.when(url, 'when');
resourceLoader.expect(url, 'expect');
expectResponse(resourceLoader.get(url), url, 'expect');
expectResponse(resourceLoader.get(url), url, 'when', () => async.done());
resourceLoader.flush();
}));
it('should throw when there is no definitions or expectations', () => {
resourceLoader.get('/foo');
expect(() => { resourceLoader.flush(); }).toThrowError('Unexpected request /foo');
});
it('should throw when flush is called without any pending requests', () => {
expect(() => { resourceLoader.flush(); }).toThrowError('No pending requests to flush');
});
it('should throw on unsatisfied expectations', () => {
resourceLoader.expect('/foo', 'bar');
resourceLoader.when('/bar', 'foo');
resourceLoader.get('/bar');
expect(() => { resourceLoader.flush(); }).toThrowError('Unsatisfied requests: /foo');
//.........这里部分代码省略.........
示例8: afterEach
t.describe('URL sanitizer', () => {
let logMsgs: string[];
let originalLog: (msg: any) => any;
t.beforeEach(() => {
logMsgs = [];
originalLog = console.warn; // Monkey patch DOM.log.
console.warn = (msg: any) => logMsgs.push(msg);
});
afterEach(() => { console.warn = originalLog; });
t.it('reports unsafe URLs', () => {
t.expect(_sanitizeUrl('javascript:evil()')).toBe('unsafe:javascript:evil()');
t.expect(logMsgs.join('\n')).toMatch(/sanitizing unsafe URL value/);
});
t.describe('valid URLs', () => {
const validUrls = [
'',
'http://abc',
'HTTP://abc',
'https://abc',
'HTTPS://abc',
'ftp://abc',
'FTP://abc',
'mailto:me@example.com',
'MAILTO:me@example.com',
'tel:123-123-1234',
'TEL:123-123-1234',
'#anchor',
'/page1.md',
'http://JavaScript/my.js',
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/', // Truncated.
'data:video/webm;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
'data:audio/opus;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
];
for (const url of validUrls) {
t.it(`valid ${url}`, () => t.expect(_sanitizeUrl(url)).toEqual(url));
}
});
t.describe('invalid URLs', () => {
const invalidUrls = [
'javascript:evil()',
'JavaScript:abc',
'evilNewProtocol:abc',
' \n Java\n Script:abc',
'javascript:',
'javascript:',
'j avascript:',
'javascript:',
'javascript:',
'jav	ascript:alert();',
'jav\u0000ascript:alert();',
'data:;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
'data:,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
'data:iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
'data:text/javascript;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
'data:application/x-msdownload;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
];
for (const url of invalidUrls) {
t.it(`valid ${url}`, () => t.expect(_sanitizeUrl(url)).toMatch(/^unsafe:/));
}
});
t.describe('valid srcsets', () => {
const validSrcsets = [
'',
'http://angular.io/images/test.png',
'http://angular.io/images/test.png, http://angular.io/images/test.png',
'http://angular.io/images/test.png, http://angular.io/images/test.png, http://angular.io/images/test.png',
'http://angular.io/images/test.png 2x',
'http://angular.io/images/test.png 2x, http://angular.io/images/test.png 3x',
'http://angular.io/images/test.png 1.5x',
'http://angular.io/images/test.png 1.25x',
'http://angular.io/images/test.png 200w, http://angular.io/images/test.png 300w',
'https://angular.io/images/test.png, http://angular.io/images/test.png',
'http://angular.io:80/images/test.png, http://angular.io:8080/images/test.png',
'http://www.angular.io:80/images/test.png, http://www.angular.io:8080/images/test.png',
'https://angular.io/images/test.png, https://angular.io/images/test.png',
'//angular.io/images/test.png, //angular.io/images/test.png',
'/images/test.png, /images/test.png',
'images/test.png, images/test.png',
'http://angular.io/images/test.png?12345, http://angular.io/images/test.png?12345',
'http://angular.io/images/test.png?maxage, http://angular.io/images/test.png?maxage',
'http://angular.io/images/test.png?maxage=234, http://angular.io/images/test.png?maxage=234',
];
for (const srcset of validSrcsets) {
t.it(`valid ${srcset}`, () => t.expect(sanitizeSrcset(srcset)).toEqual(srcset));
}
});
t.describe('invalid srcsets', () => {
const invalidSrcsets = [
'ht:tp://angular.io/images/test.png',
'http://angular.io/images/test.png, ht:tp://angular.io/images/test.png',
];
for (const srcset of invalidSrcsets) {
t.it(`valid ${srcset}`, () => t.expect(sanitizeSrcset(srcset)).toMatch(/unsafe:/));
//.........这里部分代码省略.........