test: clean up internal testing utilities (#42177)
We have some internal proxies for all of the Jasmine functions, as well as some other helpers. This code hasn't been touched in more than 5 years, it can lead to confusion and it isn't really necessary since the same can be achieved using Jasmine. These changes remove most of the code and clean up our existing unit tests. PR Close #42177
This commit is contained in:
parent
bd51762d6e
commit
a787f78074
|
@ -6,8 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {Injector, Metric, MultiMetric} from '../../index';
|
||||
|
||||
(function() {
|
||||
|
@ -22,29 +20,27 @@ function createMetric(ids: any[]) {
|
|||
}
|
||||
|
||||
describe('multi metric', () => {
|
||||
it('should merge descriptions', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should merge descriptions', done => {
|
||||
createMetric(['m1', 'm2']).then((m) => {
|
||||
expect(m.describe()).toEqual({'m1': 'describe', 'm2': 'describe'});
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should merge all beginMeasure calls',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should merge all beginMeasure calls', done => {
|
||||
createMetric(['m1', 'm2']).then((m) => m.beginMeasure()).then((values) => {
|
||||
expect(values).toEqual(['m1_beginMeasure', 'm2_beginMeasure']);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
[false, true].forEach((restartFlag) => {
|
||||
it(`should merge all endMeasure calls for restart=${restartFlag}`,
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it(`should merge all endMeasure calls for restart=${restartFlag}`, done => {
|
||||
createMetric(['m1', 'm2']).then((m) => m.endMeasure(restartFlag)).then((values) => {
|
||||
expect(values).toEqual({'m1': {'restart': restartFlag}, 'm2': {'restart': restartFlag}});
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {StaticProvider} from '@angular/core';
|
||||
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {Injector, Metric, Options, PerfLogEvent, PerfLogFeatures, PerflogMetric, WebDriverExtension} from '../../index';
|
||||
import {TraceEventFactory} from '../trace_event_factory';
|
||||
|
@ -130,30 +129,27 @@ describe('perflog metric', () => {
|
|||
});
|
||||
|
||||
describe('beginMeasure', () => {
|
||||
it('should not force gc and mark the timeline',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should not force gc and mark the timeline', done => {
|
||||
const metric = createMetric([[]], null!);
|
||||
metric.beginMeasure().then((_) => {
|
||||
expect(commandLog).toEqual([['timeBegin', 'benchpress0']]);
|
||||
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should force gc and mark the timeline',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should force gc and mark the timeline', done => {
|
||||
const metric = createMetric([[]], null!, {forceGc: true});
|
||||
metric.beginMeasure().then((_) => {
|
||||
expect(commandLog).toEqual([['gc'], ['timeBegin', 'benchpress0']]);
|
||||
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('endMeasure', () => {
|
||||
it('should mark and aggregate events in between the marks',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should mark and aggregate events in between the marks', done => {
|
||||
const events = [[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||
eventFactory.end('script', 6), eventFactory.markEnd('benchpress0', 10)
|
||||
|
@ -165,12 +161,11 @@ describe('perflog metric', () => {
|
|||
]);
|
||||
expect(data['scriptTime']).toBe(2);
|
||||
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should mark and aggregate events since navigationStart',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should mark and aggregate events since navigationStart', done => {
|
||||
const events = [[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||
eventFactory.end('script', 6), eventFactory.instant('navigationStart', 7),
|
||||
|
@ -181,12 +176,11 @@ describe('perflog metric', () => {
|
|||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(data['scriptTime']).toBe(1);
|
||||
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should ignore navigationStart if ignoreNavigation is set',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should ignore navigationStart if ignoreNavigation is set', done => {
|
||||
const events = [[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 4),
|
||||
eventFactory.end('script', 6), eventFactory.instant('navigationStart', 7),
|
||||
|
@ -197,11 +191,11 @@ describe('perflog metric', () => {
|
|||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(data['scriptTime']).toBe(3);
|
||||
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should restart timing', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should restart timing', done => {
|
||||
const events = [
|
||||
[
|
||||
eventFactory.markStart('benchpress0', 0),
|
||||
|
@ -220,12 +214,11 @@ describe('perflog metric', () => {
|
|||
'readPerfLog', ['timeEnd', 'benchpress1', 'benchpress2'], 'readPerfLog'
|
||||
]);
|
||||
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should loop and aggregate until the end mark is present',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should loop and aggregate until the end mark is present', done => {
|
||||
const events = [
|
||||
[eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 1)],
|
||||
[eventFactory.end('script', 2)],
|
||||
|
@ -242,12 +235,11 @@ describe('perflog metric', () => {
|
|||
]);
|
||||
expect(data['scriptTime']).toBe(3);
|
||||
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should store events after the end mark for the next call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should store events after the end mark for the next call', done => {
|
||||
const events = [
|
||||
[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.markEnd('benchpress0', 1),
|
||||
|
@ -273,9 +265,9 @@ describe('perflog metric', () => {
|
|||
]);
|
||||
expect(data['scriptTime']).toBe(3);
|
||||
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
describe('with forced gc', () => {
|
||||
let events: PerfLogEvent[][];
|
||||
|
@ -290,7 +282,7 @@ describe('perflog metric', () => {
|
|||
]];
|
||||
});
|
||||
|
||||
it('should measure forced gc', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should measure forced gc', done => {
|
||||
const metric = createMetric(events, null!, {forceGc: true});
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(commandLog).toEqual([
|
||||
|
@ -300,19 +292,18 @@ describe('perflog metric', () => {
|
|||
expect(data['forcedGcTime']).toBe(3);
|
||||
expect(data['forcedGcAmount']).toBe(1.5);
|
||||
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should restart after the forced gc if needed',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should restart after the forced gc if needed', done => {
|
||||
const metric = createMetric(events, null!, {forceGc: true});
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(true)).then((data) => {
|
||||
expect(commandLog[5]).toEqual(['timeEnd', 'benchpress1', 'benchpress2']);
|
||||
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -335,8 +326,7 @@ describe('perflog metric', () => {
|
|||
}
|
||||
|
||||
describe('frame metrics', () => {
|
||||
it('should calculate mean frame time',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should calculate mean frame time', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||
|
@ -346,76 +336,66 @@ describe('perflog metric', () => {
|
|||
{captureFrames: true})
|
||||
.then((data) => {
|
||||
expect(data['frameTime.mean']).toBe(((3 - 1) + (4 - 3)) / 2);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should throw if no start event',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should throw if no start event', done => {
|
||||
aggregate([eventFactory.instant('frame', 4), eventFactory.markEnd('frameCapture', 5)], {
|
||||
captureFrames: true
|
||||
}).catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('missing start event for frame capture');
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should throw if no end event',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate(
|
||||
[eventFactory.markStart('frameCapture', 3), eventFactory.instant('frame', 4)],
|
||||
{captureFrames: true})
|
||||
.catch((err): any => {
|
||||
it('should throw if no end event', done => {
|
||||
aggregate([eventFactory.markStart('frameCapture', 3), eventFactory.instant('frame', 4)], {
|
||||
captureFrames: true
|
||||
}).catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('missing end event for frame capture');
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should throw if trying to capture twice',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should throw if trying to capture twice', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 3),
|
||||
eventFactory.markStart('frameCapture', 4)
|
||||
],
|
||||
[eventFactory.markStart('frameCapture', 3), eventFactory.markStart('frameCapture', 4)],
|
||||
{captureFrames: true})
|
||||
.catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('can capture frames only once per benchmark run');
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should throw if trying to capture when frame capture is disabled',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should throw if trying to capture when frame capture is disabled', done => {
|
||||
aggregate([eventFactory.markStart('frameCapture', 3)]).catch((err) => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
})
|
||||
.toThrowError(
|
||||
'found start event for frame capture, but frame capture was not requested in benchpress');
|
||||
async.done();
|
||||
done();
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should throw if frame capture is enabled, but nothing is captured',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should throw if frame capture is enabled, but nothing is captured', done => {
|
||||
aggregate([], {captureFrames: true}).catch((err): any => {
|
||||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('frame capture requested in benchpress, but no start event was found');
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should calculate best and worst frame time',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should calculate best and worst frame time', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||
|
@ -427,12 +407,11 @@ describe('perflog metric', () => {
|
|||
.then((data) => {
|
||||
expect(data['frameTime.worst']).toBe(10);
|
||||
expect(data['frameTime.best']).toBe(3);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should calculate percentage of smoothness to be good',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should calculate percentage of smoothness to be good', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||
|
@ -442,12 +421,11 @@ describe('perflog metric', () => {
|
|||
{captureFrames: true})
|
||||
.then((data) => {
|
||||
expect(data['frameTime.smooth']).toBe(1.0);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should calculate percentage of smoothness to be bad',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should calculate percentage of smoothness to be bad', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('frameCapture', 0), eventFactory.instant('frame', 1),
|
||||
|
@ -458,117 +436,99 @@ describe('perflog metric', () => {
|
|||
{captureFrames: true})
|
||||
.then((data) => {
|
||||
expect(data['frameTime.smooth']).toBe(0.75);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should report a single interval',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.end('script', 5)
|
||||
]).then((data) => {
|
||||
it('should report a single interval', done => {
|
||||
aggregate([eventFactory.start('script', 0), eventFactory.end('script', 5)]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(5);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should sum up multiple intervals',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should sum up multiple intervals', done => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.end('script', 5),
|
||||
eventFactory.start('script', 10), eventFactory.end('script', 17)
|
||||
]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(12);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should ignore not started intervals',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should ignore not started intervals', done => {
|
||||
aggregate([eventFactory.end('script', 10)]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(0);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should ignore not ended intervals',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should ignore not ended intervals', done => {
|
||||
aggregate([eventFactory.start('script', 10)]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(0);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should ignore nested intervals',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should ignore nested intervals', done => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.start('script', 5),
|
||||
eventFactory.end('script', 10), eventFactory.end('script', 17)
|
||||
]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(17);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should ignore events from different processed as the start mark',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should ignore events from different processed as the start mark', done => {
|
||||
const otherProcessEventFactory = new TraceEventFactory('timeline', 'pid1');
|
||||
const metric = createMetric(
|
||||
[[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 0, null),
|
||||
eventFactory.end('script', 5, null),
|
||||
otherProcessEventFactory.start('script', 10, null),
|
||||
eventFactory.end('script', 5, null), otherProcessEventFactory.start('script', 10, null),
|
||||
otherProcessEventFactory.end('script', 17, null),
|
||||
eventFactory.markEnd('benchpress0', 20)
|
||||
]],
|
||||
null!);
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(data['scriptTime']).toBe(5);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should mark a run as invalid if the start and end marks are different',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should mark a run as invalid if the start and end marks are different', done => {
|
||||
const otherProcessEventFactory = new TraceEventFactory('timeline', 'pid1');
|
||||
const metric = createMetric(
|
||||
[[
|
||||
eventFactory.markStart('benchpress0', 0), eventFactory.start('script', 0, null),
|
||||
eventFactory.end('script', 5, null),
|
||||
otherProcessEventFactory.start('script', 10, null),
|
||||
eventFactory.end('script', 5, null), otherProcessEventFactory.start('script', 10, null),
|
||||
otherProcessEventFactory.end('script', 17, null),
|
||||
otherProcessEventFactory.markEnd('benchpress0', 20)
|
||||
]],
|
||||
null!);
|
||||
metric.beginMeasure().then((_) => metric.endMeasure(false)).then((data) => {
|
||||
expect(data['invalid']).toBe(1);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should support scriptTime metric',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.end('script', 5)
|
||||
]).then((data) => {
|
||||
it('should support scriptTime metric', done => {
|
||||
aggregate([eventFactory.start('script', 0), eventFactory.end('script', 5)]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(5);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should support renderTime metric',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
aggregate([
|
||||
eventFactory.start('render', 0), eventFactory.end('render', 5)
|
||||
]).then((data) => {
|
||||
it('should support renderTime metric', done => {
|
||||
aggregate([eventFactory.start('render', 0), eventFactory.end('render', 5)]).then((data) => {
|
||||
expect(data['renderTime']).toBe(5);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should support gcTime/gcAmount metric',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should support gcTime/gcAmount metric', done => {
|
||||
aggregate([
|
||||
eventFactory.start('gc', 0, {'usedHeapSize': 2500}),
|
||||
eventFactory.end('gc', 5, {'usedHeapSize': 1000})
|
||||
|
@ -576,24 +536,22 @@ describe('perflog metric', () => {
|
|||
expect(data['gcTime']).toBe(5);
|
||||
expect(data['gcAmount']).toBe(1.5);
|
||||
expect(data['majorGcTime']).toBe(0);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should support majorGcTime metric',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should support majorGcTime metric', done => {
|
||||
aggregate([
|
||||
eventFactory.start('gc', 0, {'usedHeapSize': 2500}),
|
||||
eventFactory.end('gc', 5, {'usedHeapSize': 1000, 'majorGc': true})
|
||||
]).then((data) => {
|
||||
expect(data['gcTime']).toBe(5);
|
||||
expect(data['majorGcTime']).toBe(5);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should support pureScriptTime = scriptTime-gcTime-renderTime',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should support pureScriptTime = scriptTime-gcTime-renderTime', done => {
|
||||
aggregate([
|
||||
eventFactory.start('script', 0), eventFactory.start('gc', 1, {'usedHeapSize': 1000}),
|
||||
eventFactory.end('gc', 4, {'usedHeapSize': 0}), eventFactory.start('render', 4),
|
||||
|
@ -601,13 +559,12 @@ describe('perflog metric', () => {
|
|||
]).then((data) => {
|
||||
expect(data['scriptTime']).toBe(6);
|
||||
expect(data['pureScriptTime']).toBe(2);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
describe('receivedData', () => {
|
||||
it('should report received data since last navigationStart',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report received data since last navigationStart', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.instant('receivedData', 0, {'encodedDataLength': 1}),
|
||||
|
@ -620,14 +577,13 @@ describe('perflog metric', () => {
|
|||
{receivedData: true})
|
||||
.then((data) => {
|
||||
expect(data['receivedData']).toBe(12);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('requestCount', () => {
|
||||
it('should report count of requests sent since last navigationStart',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report count of requests sent since last navigationStart', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.instant('sendRequest', 0), eventFactory.instant('navigationStart', 1),
|
||||
|
@ -637,14 +593,13 @@ describe('perflog metric', () => {
|
|||
{requestCount: true})
|
||||
.then((data) => {
|
||||
expect(data['requestCount']).toBe(2);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('microMetrics', () => {
|
||||
it('should report micro metrics',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report micro metrics', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('mm1', 0),
|
||||
|
@ -653,23 +608,21 @@ describe('perflog metric', () => {
|
|||
{microMetrics: {'mm1': 'micro metric 1'}})
|
||||
.then((data) => {
|
||||
expect(data['mm1']).toBe(5.0);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should ignore micro metrics that were not specified',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should ignore micro metrics that were not specified', done => {
|
||||
aggregate([
|
||||
eventFactory.markStart('mm1', 0),
|
||||
eventFactory.markEnd('mm1', 5),
|
||||
]).then((data) => {
|
||||
expect(data['mm1']).toBeFalsy();
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report micro metric averages',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report micro metric averages', done => {
|
||||
aggregate(
|
||||
[
|
||||
eventFactory.markStart('mm1*20', 0),
|
||||
|
@ -678,9 +631,9 @@ describe('perflog metric', () => {
|
|||
{microMetrics: {'mm1': 'micro metric 1'}})
|
||||
.then((data) => {
|
||||
expect(data['mm1']).toBe(5 / 20);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {Injector, StaticProvider} from '@angular/core';
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {Options, PerfLogEvent, PerfLogFeatures, UserMetric, WebDriverAdapter} from '../../index';
|
||||
|
||||
|
@ -42,15 +41,14 @@ describe('user metric', () => {
|
|||
});
|
||||
|
||||
describe('endMeasure', () => {
|
||||
it('should stop measuring when all properties have numeric values',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should stop measuring when all properties have numeric values', done => {
|
||||
const metric = createMetric(
|
||||
[[]], new PerfLogFeatures(),
|
||||
{userMetrics: {'loadTime': 'time to load', 'content': 'time to see content'}});
|
||||
metric.beginMeasure().then(() => metric.endMeasure(true)).then(values => {
|
||||
expect(values['loadTime']).toBe(25);
|
||||
expect(values['content']).toBe(250);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
|
||||
wdAdapter.data['loadTime'] = 25;
|
||||
|
@ -58,7 +56,7 @@ describe('user metric', () => {
|
|||
setTimeout(() => {
|
||||
wdAdapter.data['content'] = 250;
|
||||
}, 50);
|
||||
}), 600);
|
||||
}, 600);
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {StaticProvider} from '@angular/core';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {ConsoleReporter, Injector, MeasureValues, SampleDescription} from '../../index';
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {Injector, JsonFileReporter, MeasureValues, Options, SampleDescription} from '../../index';
|
||||
|
||||
{
|
||||
|
@ -37,8 +35,7 @@ import {Injector, JsonFileReporter, MeasureValues, Options, SampleDescription} f
|
|||
return Injector.create(providers).get<JsonFileReporter>(JsonFileReporter);
|
||||
}
|
||||
|
||||
it('should write all data into a file',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should write all data into a file', done => {
|
||||
createReporter({
|
||||
sampleId: 'someId',
|
||||
descriptions: [{'a': 2}],
|
||||
|
@ -58,16 +55,15 @@ import {Injector, JsonFileReporter, MeasureValues, Options, SampleDescription} f
|
|||
'metrics': {'a': 'script time', 'b': 'render time'}
|
||||
},
|
||||
'stats': {'a': '4.00+-25%', 'b': '7.50+-20%'},
|
||||
'completeSample': [
|
||||
{'timeStamp': '1970-01-01T00:00:00.000Z', 'runIndex': 0, 'values': {'a': 3, 'b': 6}}
|
||||
],
|
||||
'completeSample':
|
||||
[{'timeStamp': '1970-01-01T00:00:00.000Z', 'runIndex': 0, 'values': {'a': 3, 'b': 6}}],
|
||||
'validSample': [
|
||||
{'timeStamp': '1970-01-01T00:00:00.000Z', 'runIndex': 0, 'values': {'a': 3, 'b': 6}},
|
||||
{'timeStamp': '1970-01-01T00:00:00.001Z', 'runIndex': 1, 'values': {'a': 5, 'b': 9}}
|
||||
]
|
||||
});
|
||||
async.done();
|
||||
}));
|
||||
done();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {Injector, MeasureValues, MultiReporter, Reporter} from '../../index';
|
||||
|
||||
(function() {
|
||||
|
@ -22,16 +20,15 @@ function createReporters(ids: any[]) {
|
|||
}
|
||||
|
||||
describe('multi reporter', () => {
|
||||
it('should reportMeasureValues to all',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should reportMeasureValues to all', done => {
|
||||
const mv = new MeasureValues(0, new Date(), {});
|
||||
createReporters(['m1', 'm2']).then((r) => r.reportMeasureValues(mv)).then((values) => {
|
||||
expect(values).toEqual([{'id': 'm1', 'values': mv}, {'id': 'm2', 'values': mv}]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should reportSample to call', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should reportSample to call', done => {
|
||||
const completeSample =
|
||||
[new MeasureValues(0, new Date(), {}), new MeasureValues(1, new Date(), {})];
|
||||
const validSample = [completeSample[1]];
|
||||
|
@ -43,9 +40,9 @@ describe('multi reporter', () => {
|
|||
{'id': 'm1', 'completeSample': completeSample, 'validSample': validSample},
|
||||
{'id': 'm2', 'completeSample': completeSample, 'validSample': validSample}
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
})();
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {Injector, Metric, Options, Runner, SampleDescription, Sampler, SampleState, Validator, WebDriverAdapter} from '../index';
|
||||
|
||||
{
|
||||
|
@ -35,19 +33,17 @@ import {Injector, Metric, Options, Runner, SampleDescription, Sampler, SampleSta
|
|||
return runner;
|
||||
}
|
||||
|
||||
it('should set SampleDescription.id',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should set SampleDescription.id', done => {
|
||||
createRunner()
|
||||
.sample({id: 'someId'})
|
||||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.id).toBe('someId');
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should merge SampleDescription.description',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should merge SampleDescription.description', done => {
|
||||
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
||||
.sample({
|
||||
id: 'someId',
|
||||
|
@ -56,51 +52,45 @@ import {Injector, Metric, Options, Runner, SampleDescription, Sampler, SampleSta
|
|||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.description)
|
||||
.toEqual(
|
||||
{'forceGc': false, 'userAgent': 'someUserAgent', 'a': 1, 'b': 2, 'v': 11});
|
||||
async.done();
|
||||
.toEqual({'forceGc': false, 'userAgent': 'someUserAgent', 'a': 1, 'b': 2, 'v': 11});
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should fill SampleDescription.metrics from the Metric',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should fill SampleDescription.metrics from the Metric', done => {
|
||||
createRunner()
|
||||
.sample({id: 'someId'})
|
||||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.metrics).toEqual({'m1': 'some metric'});
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should provide Options.EXECUTE',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should provide Options.EXECUTE', done => {
|
||||
const execute = () => {};
|
||||
createRunner().sample({id: 'someId', execute: execute}).then((_) => {
|
||||
expect(injector.get(Options.EXECUTE)).toEqual(execute);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should provide Options.PREPARE',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should provide Options.PREPARE', done => {
|
||||
const prepare = () => {};
|
||||
createRunner().sample({id: 'someId', prepare: prepare}).then((_) => {
|
||||
expect(injector.get(Options.PREPARE)).toEqual(prepare);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should provide Options.MICRO_METRICS',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should provide Options.MICRO_METRICS', done => {
|
||||
createRunner().sample({id: 'someId', microMetrics: {'a': 'b'}}).then((_) => {
|
||||
expect(injector.get(Options.MICRO_METRICS)).toEqual({'a': 'b'});
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should overwrite providers per sample call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should overwrite providers per sample call', done => {
|
||||
createRunner([{provide: Options.DEFAULT_DESCRIPTION, useValue: {'a': 1}}])
|
||||
.sample({
|
||||
id: 'someId',
|
||||
|
@ -109,9 +99,9 @@ import {Injector, Metric, Options, Runner, SampleDescription, Sampler, SampleSta
|
|||
.then((_) => injector.get(SampleDescription))
|
||||
.then((desc) => {
|
||||
expect(desc.description['a']).toBe(2);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator, WebDriverAdapter} from '../index';
|
||||
|
||||
{
|
||||
|
@ -47,8 +45,7 @@ import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator,
|
|||
sampler = Injector.create(providers).get(Sampler);
|
||||
}
|
||||
|
||||
it('should call the prepare and execute callbacks using WebDriverAdapter.waitFor',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call the prepare and execute callbacks using WebDriverAdapter.waitFor', done => {
|
||||
const log: any[] = [];
|
||||
let count = 0;
|
||||
const driver = new MockDriverAdapter([], (callback: Function) => {
|
||||
|
@ -65,12 +62,11 @@ import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator,
|
|||
sampler.sample().then((_) => {
|
||||
expect(count).toBe(4);
|
||||
expect(log).toEqual([0, 1, 2, 3]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should call prepare, beginMeasure, execute, endMeasure for every iteration',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call prepare, beginMeasure, execute, endMeasure for every iteration', done => {
|
||||
let workCount = 0;
|
||||
const log: any[] = [];
|
||||
createSampler({
|
||||
|
@ -94,12 +90,12 @@ import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator,
|
|||
'w3',
|
||||
['endMeasure', false, {'script': 1}],
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should call execute, endMeasure for every iteration if there is no prepare callback',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
const log: any[] = [];
|
||||
let workCount = 0;
|
||||
createSampler({
|
||||
|
@ -118,12 +114,11 @@ import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator,
|
|||
'w1',
|
||||
['endMeasure', true, {'script': 1}],
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should only collect metrics for execute and ignore metrics from prepare',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should only collect metrics for execute and ignore metrics from prepare', done => {
|
||||
let scriptTime = 0;
|
||||
let iterationCount = 1;
|
||||
createSampler({
|
||||
|
@ -147,12 +142,11 @@ import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator,
|
|||
expect(state.completeSample.length).toBe(2);
|
||||
expect(state.completeSample[0]).toEqual(mv(0, 1000, {'script': 10}));
|
||||
expect(state.completeSample[1]).toEqual(mv(1, 1001, {'script': 20}));
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should call the validator for every execution and store the valid sample',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call the validator for every execution and store the valid sample', done => {
|
||||
const log: any[] = [];
|
||||
const validSample = [mv(null!, null!, {})];
|
||||
|
||||
|
@ -174,12 +168,11 @@ import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator,
|
|||
expect(log[1]).toEqual(
|
||||
['validate', [mv(0, 1000, {'script': 0}), mv(1, 1001, {'script': 1})], validSample]);
|
||||
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report the metric values',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report the metric values', done => {
|
||||
const log: any[] = [];
|
||||
const validSample = [mv(null!, null!, {})];
|
||||
createSampler({
|
||||
|
@ -202,9 +195,9 @@ import {Injector, MeasureValues, Metric, Options, Reporter, Sampler, Validator,
|
|||
'reportSample', [mv(0, 1000, {'script': 0}), mv(1, 1001, {'script': 1})], validSample
|
||||
]);
|
||||
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {Statistic} from '../src/statistic';
|
||||
|
||||
{
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {Injector, MeasureValues, RegressionSlopeValidator} from '../../index';
|
||||
|
||||
{
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {Injector, MeasureValues, SizeValidator} from '../../index';
|
||||
|
||||
{
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {Injector, Options, WebDriverExtension} from '../index';
|
||||
|
||||
(function() {
|
||||
|
@ -28,21 +26,19 @@ function createExtension(ids: any[], caps: any) {
|
|||
}
|
||||
|
||||
describe('WebDriverExtension.provideFirstSupported', () => {
|
||||
it('should provide the extension that matches the capabilities',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should provide the extension that matches the capabilities', done => {
|
||||
createExtension(['m1', 'm2', 'm3'], {'browser': 'm2'}).then((m) => {
|
||||
expect(m.id).toEqual('m2');
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should throw if there is no match',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should throw if there is no match', done => {
|
||||
createExtension(['m1'], {'browser': 'm2'}).catch((err) => {
|
||||
expect(err != null).toBe(true);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
})();
|
||||
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AsyncTestCompleter, describe, expect, fit, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {ChromeDriverExtension, Injector, Options, WebDriverAdapter, WebDriverExtension} from '../../index';
|
||||
import {TraceEventFactory} from '../trace_event_factory';
|
||||
|
||||
|
@ -54,26 +52,24 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
return extension;
|
||||
}
|
||||
|
||||
it('should force gc via window.gc()',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should force gc via window.gc()', done => {
|
||||
createExtension().gc().then((_) => {
|
||||
expect(log).toEqual([['executeScript', 'window.gc()']]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should clear the perf logs and mark the timeline via performance.mark() on the first call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
createExtension().timeBegin('someName').then(() => {
|
||||
expect(log).toEqual([
|
||||
['logs', 'performance'], ['executeScript', `performance.mark('someName-bpstart');`]
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should mark the timeline via performance.mark() on the second call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should mark the timeline via performance.mark() on the second call', done => {
|
||||
const ext = createExtension();
|
||||
ext.timeBegin('someName')
|
||||
.then((_) => {
|
||||
|
@ -82,77 +78,71 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
})
|
||||
.then(() => {
|
||||
expect(log).toEqual([['executeScript', `performance.mark('someName-bpstart');`]]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should mark the timeline via performance.mark()',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should mark the timeline via performance.mark()', done => {
|
||||
createExtension().timeEnd('someName', null).then((_) => {
|
||||
expect(log).toEqual([['executeScript', `performance.mark('someName-bpend');`]]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should mark the timeline via performance.mark() with start and end of a test',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should mark the timeline via performance.mark() with start and end of a test', done => {
|
||||
createExtension().timeEnd('name1', 'name2').then((_) => {
|
||||
expect(log).toEqual([
|
||||
['executeScript', `performance.mark('name1-bpend');performance.mark('name2-bpstart');`]
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should normalize times to ms and forward ph and pid event properties',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should normalize times to ms and forward ph and pid event properties', done => {
|
||||
createExtension([chromeTimelineV8Events.complete('FunctionCall', 1100, 5500, null)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.complete('script', 1.1, 5.5, null),
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should normalize "tdur" to "dur"',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should normalize "tdur" to "dur"', done => {
|
||||
const event: any = chromeTimelineV8Events.create('X', 'FunctionCall', 1100, null);
|
||||
event['tdur'] = 5500;
|
||||
createExtension([event]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.complete('script', 1.1, 5.5, null),
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report FunctionCall events as "script"',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report FunctionCall events as "script"', done => {
|
||||
createExtension([chromeTimelineV8Events.start('FunctionCall', 0)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.start('script', 0),
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report EvaluateScript events as "script"',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report EvaluateScript events as "script"', done => {
|
||||
createExtension([chromeTimelineV8Events.start('EvaluateScript', 0)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.start('script', 0),
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report minor gc', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report minor gc', done => {
|
||||
createExtension([
|
||||
chromeTimelineV8Events.start('MinorGC', 1000, {'usedHeapSizeBefore': 1000}),
|
||||
chromeTimelineV8Events.end('MinorGC', 2000, {'usedHeapSizeAfter': 0}),
|
||||
|
@ -164,11 +154,11 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
normEvents.start('gc', 1.0, {'usedHeapSize': 1000, 'majorGc': false}));
|
||||
expect(events[1]).toEqual(
|
||||
normEvents.end('gc', 2.0, {'usedHeapSize': 0, 'majorGc': false}));
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report major gc', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report major gc', done => {
|
||||
createExtension(
|
||||
[
|
||||
chromeTimelineV8Events.start('MajorGC', 1000, {'usedHeapSizeBefore': 1000}),
|
||||
|
@ -182,13 +172,12 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
normEvents.start('gc', 1.0, {'usedHeapSize': 1000, 'majorGc': true}));
|
||||
expect(events[1]).toEqual(
|
||||
normEvents.end('gc', 2.0, {'usedHeapSize': 0, 'majorGc': true}));
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
['Layout', 'UpdateLayerTree', 'Paint'].forEach((recordType) => {
|
||||
it(`should report ${recordType} as "render"`,
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it(`should report ${recordType} as "render"`, done => {
|
||||
createExtension(
|
||||
[
|
||||
chrome45TimelineEvents.start(recordType, 1234),
|
||||
|
@ -201,13 +190,12 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
normEvents.start('render', 1.234),
|
||||
normEvents.end('render', 2.345),
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it(`should report UpdateLayoutTree as "render"`,
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it(`should report UpdateLayoutTree as "render"`, done => {
|
||||
createExtension(
|
||||
[
|
||||
chromeBlinkTimelineEvents.start('UpdateLayoutTree', 1234),
|
||||
|
@ -220,43 +208,40 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
normEvents.start('render', 1.234),
|
||||
normEvents.end('render', 2.345),
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should ignore FunctionCalls from webdriver',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should ignore FunctionCalls from webdriver', done => {
|
||||
createExtension([chromeTimelineV8Events.start(
|
||||
'FunctionCall', 0, {'data': {'scriptName': 'InjectedScript'}})])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should ignore FunctionCalls with empty scriptName',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should ignore FunctionCalls with empty scriptName', done => {
|
||||
createExtension(
|
||||
[chromeTimelineV8Events.start('FunctionCall', 0, {'data': {'scriptName': ''}})])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report navigationStart',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report navigationStart', done => {
|
||||
createExtension([chromeBlinkUserTimingEvents.instant('navigationStart', 1234)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([normEvents.instant('navigationStart', 1.234)]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report receivedData', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report receivedData', done => {
|
||||
createExtension(
|
||||
[chrome45TimelineEvents.instant(
|
||||
'ResourceReceivedData', 1234, {'data': {'encodedDataLength': 987}})],
|
||||
|
@ -265,11 +250,11 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
.then((events) => {
|
||||
expect(events).toEqual(
|
||||
[normEvents.instant('receivedData', 1.234, {'encodedDataLength': 987})]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report sendRequest', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report sendRequest', done => {
|
||||
createExtension(
|
||||
[chrome45TimelineEvents.instant(
|
||||
'ResourceSendRequest', 1234,
|
||||
|
@ -279,25 +264,23 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
.then((events) => {
|
||||
expect(events).toEqual([normEvents.instant(
|
||||
'sendRequest', 1.234, {'url': 'http://here', 'method': 'GET'})]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
describe('readPerfLog (common)', () => {
|
||||
it('should execute a dummy script before reading them',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should execute a dummy script before reading them', done => {
|
||||
// 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();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
['Rasterize', 'CompositeLayers'].forEach((recordType) => {
|
||||
it(`should report ${recordType} as "render"`,
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it(`should report ${recordType} as "render"`, done => {
|
||||
createExtension(
|
||||
[
|
||||
chromeTimelineEvents.start(recordType, 1234),
|
||||
|
@ -310,14 +293,13 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
normEvents.start('render', 1.234),
|
||||
normEvents.end('render', 2.345),
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
describe('frame metrics', () => {
|
||||
it('should report ImplThreadRenderingStats as frame event',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report ImplThreadRenderingStats as frame event', done => {
|
||||
createExtension([benchmarkEvents.instant(
|
||||
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
||||
{'data': {'frame_count': 1}})])
|
||||
|
@ -326,24 +308,22 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
expect(events).toEqual([
|
||||
normEvents.instant('frame', 1.1),
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not report ImplThreadRenderingStats with zero frames',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should not report ImplThreadRenderingStats with zero frames', done => {
|
||||
createExtension([benchmarkEvents.instant(
|
||||
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
||||
{'data': {'frame_count': 0}})])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should throw when ImplThreadRenderingStats contains more than one frame',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should throw when ImplThreadRenderingStats contains more than one frame', done => {
|
||||
createExtension([benchmarkEvents.instant(
|
||||
'BenchmarkInstrumentation::ImplThreadRenderingStats', 1100,
|
||||
{'data': {'frame_count': 2}})])
|
||||
|
@ -352,33 +332,30 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('multi-frame render stats not supported');
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should report begin timestamps',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report begin timestamps', done => {
|
||||
createExtension([blinkEvents.create('S', 'someName', 1000)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([normEvents.markStart('someName', 1.0)]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report end timestamps',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report end timestamps', done => {
|
||||
createExtension([blinkEvents.create('F', 'someName', 1000)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
expect(events).toEqual([normEvents.markEnd('someName', 1.0)]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should throw an error on buffer overflow',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should throw an error on buffer overflow', done => {
|
||||
createExtension(
|
||||
[
|
||||
chromeTimelineEvents.start('FunctionCall', 1234),
|
||||
|
@ -389,9 +366,9 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
expect(() => {
|
||||
throw err;
|
||||
}).toThrowError('The DevTools trace buffer filled during the test!');
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should match chrome browsers', () => {
|
||||
expect(createExtension().supports({'browserName': 'chrome'})).toBe(true);
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AsyncTestCompleter, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {Injector, IOsDriverExtension, WebDriverAdapter, WebDriverExtension} from '../../index';
|
||||
import {TraceEventFactory} from '../trace_event_factory';
|
||||
|
||||
|
@ -37,92 +35,81 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
expect(() => createExtension().gc()).toThrowError('Force GC is not supported on iOS');
|
||||
});
|
||||
|
||||
it('should mark the timeline via console.time()',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should mark the timeline via console.time()', done => {
|
||||
createExtension().timeBegin('someName').then((_) => {
|
||||
expect(log).toEqual([['executeScript', `console.time('someName');`]]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should mark the timeline via console.timeEnd()',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should mark the timeline via console.timeEnd()', done => {
|
||||
createExtension().timeEnd('someName', null).then((_) => {
|
||||
expect(log).toEqual([['executeScript', `console.timeEnd('someName');`]]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should mark the timeline via console.time() and console.timeEnd()',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should mark the timeline via console.time() and console.timeEnd()', done => {
|
||||
createExtension().timeEnd('name1', 'name2').then((_) => {
|
||||
expect(log).toEqual(
|
||||
[['executeScript', `console.timeEnd('name1');console.time('name2');`]]);
|
||||
async.done();
|
||||
expect(log).toEqual([['executeScript', `console.timeEnd('name1');console.time('name2');`]]);
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
describe('readPerfLog', () => {
|
||||
it('should execute a dummy script before reading them',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should execute a dummy script before reading them', done => {
|
||||
// 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();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report FunctionCall records as "script"',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report FunctionCall records as "script"', done => {
|
||||
createExtension([durationRecord('FunctionCall', 1, 5)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([normEvents.start('script', 1), normEvents.end('script', 5)]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should ignore FunctionCalls from webdriver',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should ignore FunctionCalls from webdriver', done => {
|
||||
createExtension([internalScriptRecord(1, 5)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report begin time', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report begin time', done => {
|
||||
createExtension([timeBeginRecord('someName', 12)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([normEvents.markStart('someName', 12)]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should report end timestamps',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should report end timestamps', done => {
|
||||
createExtension([timeEndRecord('someName', 12)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([normEvents.markEnd('someName', 12)]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
['RecalculateStyles', 'Layout', 'UpdateLayerTree', 'Paint', 'Rasterize', 'CompositeLayers']
|
||||
.forEach((recordType) => {
|
||||
it(`should report ${recordType}`,
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
createExtension([durationRecord(recordType, 0, 1)])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
it(`should report ${recordType}`, done => {
|
||||
createExtension([durationRecord(recordType, 0, 1)]).readPerfLog().then((events) => {
|
||||
expect(events).toEqual([
|
||||
normEvents.start('render', 0),
|
||||
normEvents.end('render', 1),
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
it('should walk children', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should walk children', done => {
|
||||
createExtension([durationRecord('FunctionCall', 1, 5, [timeBeginRecord('someName', 2)])])
|
||||
.readPerfLog()
|
||||
.then((events) => {
|
||||
|
@ -130,9 +117,9 @@ import {TraceEventFactory} from '../trace_event_factory';
|
|||
normEvents.start('script', 1), normEvents.markStart('someName', 2),
|
||||
normEvents.end('script', 5)
|
||||
]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should match safari browsers', () => {
|
||||
expect(createExtension().supports({'browserName': 'safari'})).toBe(true);
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import {HttpClient} from '@angular/common/http/src/client';
|
||||
import {HttpErrorResponse, HttpEventType, HttpResponse, HttpStatusCode} from '@angular/common/http/src/response';
|
||||
import {HttpClientTestingBackend} from '@angular/common/http/testing/src/backend';
|
||||
import {ddescribe, describe, fit, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {toArray} from 'rxjs/operators';
|
||||
|
||||
{
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import {JSONP_ERR_NO_CALLBACK, JSONP_ERR_WRONG_METHOD, JSONP_ERR_WRONG_RESPONSE_TYPE, JsonpClientBackend} from '@angular/common/http/src/jsonp';
|
||||
import {HttpRequest} from '@angular/common/http/src/request';
|
||||
import {HttpErrorResponse, HttpEventType} from '@angular/common/http/src/response';
|
||||
import {ddescribe, describe, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {toArray} from 'rxjs/operators';
|
||||
|
||||
import {MockDocument} from './jsonp_mock';
|
||||
|
|
|
@ -10,7 +10,6 @@ import {HttpContext} from '@angular/common/http/src/context';
|
|||
import {HttpHeaders} from '@angular/common/http/src/headers';
|
||||
import {HttpParams} from '@angular/common/http/src/params';
|
||||
import {HttpRequest} from '@angular/common/http/src/request';
|
||||
import {ddescribe, describe, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
const TEST_URL = 'https://angular.io/';
|
||||
const TEST_STRING = `I'm a body!`;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {HttpHeaders} from '@angular/common/http/src/headers';
|
||||
import {HttpResponse, HttpStatusCode} from '@angular/common/http/src/response';
|
||||
import {describe, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('HttpResponse', () => {
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import {HttpRequest} from '@angular/common/http/src/request';
|
||||
import {HttpDownloadProgressEvent, HttpErrorResponse, HttpEvent, HttpEventType, HttpHeaderResponse, HttpResponse, HttpResponseBase, HttpStatusCode, HttpUploadProgressEvent} from '@angular/common/http/src/response';
|
||||
import {HttpXhrBackend} from '@angular/common/http/src/xhr';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {Observable} from 'rxjs';
|
||||
import {toArray} from 'rxjs/operators';
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
*/
|
||||
|
||||
import {parseCookieValue} from '@angular/common/src/cookie';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('cookies', () => {
|
||||
|
|
|
@ -12,7 +12,6 @@ import localeEn from '@angular/common/locales/en';
|
|||
import localeEsUS from '@angular/common/locales/es-US';
|
||||
import localeFr from '@angular/common/locales/fr';
|
||||
import {ɵDEFAULT_LOCALE_ID, ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
describe('Format number', () => {
|
||||
beforeAll(() => {
|
||||
|
|
|
@ -7,15 +7,16 @@
|
|||
*/
|
||||
|
||||
import {AsyncPipe, ɵgetDOM as getDOM} from '@angular/common';
|
||||
import {EventEmitter} from '@angular/core';
|
||||
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {ChangeDetectorRef, EventEmitter} from '@angular/core';
|
||||
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||
import {Subscribable, Unsubscribable} from 'rxjs';
|
||||
|
||||
import {SpyChangeDetectorRef} from '../spies';
|
||||
|
||||
{
|
||||
describe('AsyncPipe', () => {
|
||||
function getChangeDetectorRefSpy() {
|
||||
return jasmine.createSpyObj('ChangeDetectorRef', ['markForCheck', 'detectChanges']);
|
||||
}
|
||||
|
||||
describe('Observable', () => {
|
||||
// only expose methods from the Subscribable interface, to ensure that
|
||||
// the implementation does not rely on other methods:
|
||||
|
@ -33,13 +34,13 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
let emitter: EventEmitter<any>;
|
||||
let subscribable: Subscribable<any>;
|
||||
let pipe: AsyncPipe;
|
||||
let ref: any;
|
||||
let ref: ChangeDetectorRef&jasmine.SpyObj<ChangeDetectorRef>;
|
||||
const message = {};
|
||||
|
||||
beforeEach(() => {
|
||||
emitter = new EventEmitter();
|
||||
subscribable = wrapSubscribable(emitter);
|
||||
ref = new SpyChangeDetectorRef();
|
||||
ref = getChangeDetectorRefSpy();
|
||||
pipe = new AsyncPipe(ref);
|
||||
});
|
||||
|
||||
|
@ -48,32 +49,30 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
expect(pipe.transform(subscribable)).toBe(null);
|
||||
});
|
||||
|
||||
it('should return the latest available value',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should return the latest available value', done => {
|
||||
pipe.transform(subscribable);
|
||||
emitter.emit(message);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(subscribable)).toEqual(message);
|
||||
async.done();
|
||||
done();
|
||||
}, 0);
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
it('should return same value when nothing has changed since the last call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should return same value when nothing has changed since the last call', done => {
|
||||
pipe.transform(subscribable);
|
||||
emitter.emit(message);
|
||||
|
||||
setTimeout(() => {
|
||||
pipe.transform(subscribable);
|
||||
expect(pipe.transform(subscribable)).toBe(message);
|
||||
async.done();
|
||||
done();
|
||||
}, 0);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should dispose of the existing subscription when subscribing to a new observable',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
pipe.transform(subscribable);
|
||||
|
||||
const newEmitter = new EventEmitter();
|
||||
|
@ -84,20 +83,19 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
// this should not affect the pipe
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(newSubscribable)).toBe(null);
|
||||
async.done();
|
||||
done();
|
||||
}, 0);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should request a change detection check upon receiving a new value',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should request a change detection check upon receiving a new value', done => {
|
||||
pipe.transform(subscribable);
|
||||
emitter.emit(message);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(ref.spy('markForCheck')).toHaveBeenCalled();
|
||||
async.done();
|
||||
expect(ref.markForCheck).toHaveBeenCalled();
|
||||
done();
|
||||
}, 10);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should return value for unchanged NaN', () => {
|
||||
emitter.emit(null);
|
||||
|
@ -115,23 +113,22 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
expect(() => pipe.ngOnDestroy()).not.toThrow();
|
||||
});
|
||||
|
||||
it('should dispose of the existing subscription',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should dispose of the existing subscription', done => {
|
||||
pipe.transform(subscribable);
|
||||
pipe.ngOnDestroy();
|
||||
emitter.emit(message);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(subscribable)).toBe(null);
|
||||
async.done();
|
||||
done();
|
||||
}, 0);
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Subscribable', () => {
|
||||
it('should infer the type from the subscribable', () => {
|
||||
const ref = new SpyChangeDetectorRef() as any;
|
||||
const ref = getChangeDetectorRefSpy();
|
||||
const pipe = new AsyncPipe(ref);
|
||||
const emitter = new EventEmitter<{name: 'T'}>();
|
||||
// The following line will fail to compile if the type cannot be inferred.
|
||||
|
@ -145,7 +142,7 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
let resolve: (result: any) => void;
|
||||
let reject: (error: any) => void;
|
||||
let promise: Promise<any>;
|
||||
let ref: SpyChangeDetectorRef;
|
||||
let ref: any;
|
||||
// adds longer timers for passing tests in IE
|
||||
const timer = (getDOM() && browserDetection.isIE) ? 50 : 10;
|
||||
|
||||
|
@ -154,8 +151,8 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
resolve = res;
|
||||
reject = rej;
|
||||
});
|
||||
ref = new SpyChangeDetectorRef();
|
||||
pipe = new AsyncPipe(ref as any);
|
||||
ref = getChangeDetectorRefSpy();
|
||||
pipe = new AsyncPipe(ref);
|
||||
});
|
||||
|
||||
describe('transform', () => {
|
||||
|
@ -163,32 +160,30 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
expect(pipe.transform(promise)).toBe(null);
|
||||
});
|
||||
|
||||
it('should return the latest available value',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should return the latest available value', done => {
|
||||
pipe.transform(promise);
|
||||
|
||||
resolve(message);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(promise)).toEqual(message);
|
||||
async.done();
|
||||
done();
|
||||
}, timer);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should return value when nothing has changed since the last call',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should return value when nothing has changed since the last call', done => {
|
||||
pipe.transform(promise);
|
||||
resolve(message);
|
||||
|
||||
setTimeout(() => {
|
||||
pipe.transform(promise);
|
||||
expect(pipe.transform(promise)).toBe(message);
|
||||
async.done();
|
||||
done();
|
||||
}, timer);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should dispose of the existing subscription when subscribing to a new promise',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
pipe.transform(promise);
|
||||
|
||||
promise = new Promise<any>(() => {});
|
||||
|
@ -198,29 +193,26 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
|
||||
setTimeout(() => {
|
||||
expect(pipe.transform(promise)).toBe(null);
|
||||
async.done();
|
||||
done();
|
||||
}, timer);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should request a change detection check upon receiving a new value',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
const markForCheck = ref.spy('markForCheck');
|
||||
it('should request a change detection check upon receiving a new value', done => {
|
||||
pipe.transform(promise);
|
||||
resolve(message);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(markForCheck).toHaveBeenCalled();
|
||||
async.done();
|
||||
expect(ref.markForCheck).toHaveBeenCalled();
|
||||
done();
|
||||
}, timer);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('ngOnDestroy', () => {
|
||||
it('should do nothing when no source', () => {
|
||||
expect(() => pipe.ngOnDestroy()).not.toThrow();
|
||||
});
|
||||
|
||||
it('should dispose of the existing source',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should dispose of the existing source', done => {
|
||||
pipe.transform(promise);
|
||||
expect(pipe.transform(promise)).toBe(null);
|
||||
resolve(message);
|
||||
|
@ -230,9 +222,9 @@ import {SpyChangeDetectorRef} from '../spies';
|
|||
expect(pipe.transform(promise)).toEqual(message);
|
||||
pipe.ngOnDestroy();
|
||||
expect(pipe.transform(promise)).toBe(null);
|
||||
async.done();
|
||||
done();
|
||||
}, timer);
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {I18nPluralPipe, NgLocalization} from '@angular/common';
|
||||
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
|
||||
|
||||
{
|
||||
|
|
|
@ -14,7 +14,6 @@ import localeEn from '@angular/common/locales/en';
|
|||
import localeEsUS from '@angular/common/locales/es-US';
|
||||
import localeFr from '@angular/common/locales/fr';
|
||||
import {ɵregisterLocaleData, ɵunregisterLocaleData} from '@angular/core';
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('Number pipes', () => {
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google LLC 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 {ChangeDetectorRef} from '@angular/core/src/change_detection/change_detector_ref';
|
||||
import {SpyObject} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
export class SpyChangeDetectorRef extends SpyObject {
|
||||
constructor() {
|
||||
super(ChangeDetectorRef);
|
||||
this.spy('markForCheck');
|
||||
}
|
||||
}
|
||||
|
||||
export class SpyNgControl extends SpyObject {}
|
||||
|
||||
export class SpyValueAccessor extends SpyObject {
|
||||
writeValue: any;
|
||||
}
|
|
@ -6,7 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||
import {BrowserViewportScroller, ViewportScroller} from '../src/viewport_scroller';
|
||||
|
||||
|
|
|
@ -11,14 +11,13 @@ import {Serializer} from '@angular/compiler/src/i18n';
|
|||
import {MessageBundle} from '@angular/compiler/src/i18n/message_bundle';
|
||||
import {HtmlParser} from '@angular/compiler/src/ml_parser/html_parser';
|
||||
import {DEFAULT_INTERPOLATION_CONFIG} from '@angular/compiler/src/ml_parser/interpolation_config';
|
||||
import {ResourceLoader} from '@angular/compiler/src/resource_loader';
|
||||
import {Component, DebugElement, TRANSLATIONS, TRANSLATIONS_FORMAT} from '@angular/core';
|
||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||
import {stringifyElement} from '@angular/platform-browser/testing/src/browser_util';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
import {SpyResourceLoader} from '../spies';
|
||||
|
||||
@Component({
|
||||
selector: 'i18n-cmp',
|
||||
template: '',
|
||||
|
@ -180,7 +179,7 @@ export const HTML = `
|
|||
export async function configureCompiler(translationsToMerge: string, format: string) {
|
||||
TestBed.configureCompiler({
|
||||
providers: [
|
||||
SpyResourceLoader.PROVIDE,
|
||||
{provide: ResourceLoader, useValue: jasmine.createSpyObj('ResourceLoader', ['get'])},
|
||||
FrLocalization.PROVIDE,
|
||||
{provide: TRANSLATIONS, useValue: translationsToMerge},
|
||||
{provide: TRANSLATIONS_FORMAT, useValue: format},
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Injector, NgModule} from '@angular/core';
|
||||
import {beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {NgModule} from '@angular/core';
|
||||
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
|
||||
|
||||
import {MockNgModuleResolver} from '../testing';
|
||||
|
@ -16,9 +15,9 @@ import {MockNgModuleResolver} from '../testing';
|
|||
describe('MockNgModuleResolver', () => {
|
||||
let ngModuleResolver: MockNgModuleResolver;
|
||||
|
||||
beforeEach(inject([Injector], (injector: Injector) => {
|
||||
beforeEach(() => {
|
||||
ngModuleResolver = new MockNgModuleResolver(new JitReflector());
|
||||
}));
|
||||
});
|
||||
|
||||
describe('NgModule overriding', () => {
|
||||
it('should fallback to the default NgModuleResolver when templates are not overridden',
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {MockResourceLoader} from '@angular/compiler/testing/src/resource_loader_mock';
|
||||
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('MockResourceLoader', () => {
|
||||
|
@ -42,41 +41,37 @@ import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@ang
|
|||
request.then(onResponse, onError);
|
||||
}
|
||||
|
||||
it('should return a response from the definitions',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should return a response from the definitions', done => {
|
||||
const url = '/foo';
|
||||
const response = 'bar';
|
||||
resourceLoader.when(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
||||
expectResponse(resourceLoader.get(url), url, response, () => done());
|
||||
resourceLoader.flush();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should return an error from the definitions',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should return an error from the definitions', done => {
|
||||
const url = '/foo';
|
||||
const response: string = null!;
|
||||
resourceLoader.when(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
||||
expectResponse(resourceLoader.get(url), url, response, () => done());
|
||||
resourceLoader.flush();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should return a response from the expectations',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should return a response from the expectations', done => {
|
||||
const url = '/foo';
|
||||
const response = 'bar';
|
||||
resourceLoader.expect(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
||||
expectResponse(resourceLoader.get(url), url, response, () => done());
|
||||
resourceLoader.flush();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should return an error from the expectations',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should return an error from the expectations', done => {
|
||||
const url = '/foo';
|
||||
const response: string = null!;
|
||||
resourceLoader.expect(url, response);
|
||||
expectResponse(resourceLoader.get(url), url, response, () => async.done());
|
||||
expectResponse(resourceLoader.get(url), url, response, () => done());
|
||||
resourceLoader.flush();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should not reuse expectations', () => {
|
||||
const url = '/foo';
|
||||
|
@ -89,15 +84,14 @@ import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@ang
|
|||
}).toThrowError('Unexpected request /foo');
|
||||
});
|
||||
|
||||
it('should return expectations before definitions',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should return expectations before definitions', done => {
|
||||
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());
|
||||
expectResponse(resourceLoader.get(url), url, 'when', () => done());
|
||||
resourceLoader.flush();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should throw when there is no definitions or expectations', () => {
|
||||
resourceLoader.get('/foo');
|
||||
|
|
|
@ -13,8 +13,6 @@ import {expect} from '@angular/platform-browser/testing/src/matchers';
|
|||
|
||||
import {MockDirectiveResolver} from '../testing';
|
||||
|
||||
import {SpyResourceLoader} from './spies';
|
||||
|
||||
@Component({selector: 'child-cmp'})
|
||||
class ChildComp {
|
||||
}
|
||||
|
@ -91,22 +89,20 @@ class SomeCompWithUrlTemplate {
|
|||
|
||||
describe('RuntimeCompiler', () => {
|
||||
let compiler: Compiler;
|
||||
let resourceLoader: SpyResourceLoader;
|
||||
let resourceLoader: {get: jasmine.Spy};
|
||||
let dirResolver: MockDirectiveResolver;
|
||||
let injector: Injector;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureCompiler({providers: [SpyResourceLoader.PROVIDE]});
|
||||
resourceLoader = jasmine.createSpyObj('ResourceLoader', ['get']);
|
||||
TestBed.configureCompiler({providers: [{provide: ResourceLoader, useValue: resourceLoader}]});
|
||||
});
|
||||
|
||||
beforeEach(fakeAsync(inject(
|
||||
[Compiler, ResourceLoader, DirectiveResolver, Injector],
|
||||
(_compiler: Compiler, _resourceLoader: SpyResourceLoader,
|
||||
_dirResolver: MockDirectiveResolver, _injector: Injector) => {
|
||||
(_compiler: Compiler, _resourceLoader: any, _dirResolver: MockDirectiveResolver) => {
|
||||
compiler = _compiler;
|
||||
resourceLoader = _resourceLoader;
|
||||
dirResolver = _dirResolver;
|
||||
injector = _injector;
|
||||
})));
|
||||
|
||||
describe('compileModuleAsync', () => {
|
||||
|
@ -118,7 +114,7 @@ class SomeCompWithUrlTemplate {
|
|||
class SomeModule {
|
||||
}
|
||||
|
||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve('hello'));
|
||||
resourceLoader.get.and.callFake(() => Promise.resolve('hello'));
|
||||
let ngModuleFactory: NgModuleFactory<any> = undefined!;
|
||||
compiler.compileModuleAsync(SomeModule).then((f) => ngModuleFactory = f);
|
||||
tick();
|
||||
|
@ -133,7 +129,7 @@ class SomeCompWithUrlTemplate {
|
|||
class SomeModule {
|
||||
}
|
||||
|
||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve(''));
|
||||
resourceLoader.get.and.callFake(() => Promise.resolve(''));
|
||||
expect(() => compiler.compileModuleSync(SomeModule))
|
||||
.toThrowError(`Can't compile synchronously as ${
|
||||
stringify(SomeCompWithUrlTemplate)} is still being loaded!`);
|
||||
|
@ -145,7 +141,7 @@ class SomeCompWithUrlTemplate {
|
|||
class SomeModule {
|
||||
}
|
||||
|
||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve(''));
|
||||
resourceLoader.get.and.callFake(() => Promise.resolve(''));
|
||||
dirResolver.setDirective(SomeComp, new Component({selector: 'some-cmp', template: ''}));
|
||||
dirResolver.setDirective(
|
||||
ChildComp, new Component({selector: 'child-cmp', templateUrl: '/someTpl.html'}));
|
||||
|
@ -163,7 +159,7 @@ class SomeCompWithUrlTemplate {
|
|||
class SomeModule {
|
||||
}
|
||||
|
||||
resourceLoader.spy('get').and.callFake(() => Promise.resolve('hello'));
|
||||
resourceLoader.get.and.callFake(() => Promise.resolve('hello'));
|
||||
compiler.compileModuleAsync(SomeModule);
|
||||
tick();
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {DomElementSchemaRegistry} from '@angular/compiler/src/schema/dom_element_schema_registry';
|
||||
import {CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, SecurityContext} from '@angular/core';
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||
|
||||
import {Element} from '../../src/ml_parser/ast';
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {isTrustedTypesSink} from '@angular/compiler/src/schema/trusted_types_sinks';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('isTrustedTypesSink', () => {
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google LLC 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 {ResourceLoader} from '@angular/compiler/src/resource_loader';
|
||||
|
||||
import {SpyObject} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
export class SpyResourceLoader extends SpyObject {
|
||||
public static PROVIDE = {provide: ResourceLoader, useClass: SpyResourceLoader, deps: []};
|
||||
constructor() {
|
||||
super(ResourceLoader);
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {beforeEach, describe, expect, inject, it} from '../../../core/testing/src/testing_internal';
|
||||
import {inject} from '../../../core/testing';
|
||||
import {Element} from '../../src/ml_parser/ast';
|
||||
import {HtmlParser} from '../../src/ml_parser/html_parser';
|
||||
import {PreparsedElement, PreparsedElementType, preparseElement} from '../../src/template_parser/template_preparser';
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {createOfflineCompileUrlResolver, UrlResolver} from '@angular/compiler/src/url_resolver';
|
||||
import {beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {UrlResolver} from '@angular/compiler/src/url_resolver';
|
||||
import {inject} from '@angular/core/testing';
|
||||
|
||||
{
|
||||
describe('UrlResolver', () => {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {ApplicationRef, COMPILER_OPTIONS, Component, destroyPlatform, NgModule, NgZone, TestabilityRegistry, ViewEncapsulation} from '@angular/core';
|
||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {onlyInIvy, withBody} from '@angular/private/testing';
|
||||
|
|
|
@ -14,7 +14,6 @@ import {isLView} from '@angular/core/src/render3/interfaces/type_checks';
|
|||
import {CONTEXT} from '@angular/core/src/render3/interfaces/view';
|
||||
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import {getElementStyles} from '@angular/core/testing/src/styling';
|
||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
||||
import {onlyInIvy} from '@angular/private/testing';
|
||||
|
||||
import {getLContext} from '../../src/render3/context_discovery';
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {ProfilerEvent, setProfiler} from '@angular/core/src/render3/profiler';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
||||
import {onlyInIvy} from '@angular/private/testing';
|
||||
|
||||
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, Component, DoCheck, ErrorHandler, EventEmitter, Input, OnChanges, OnDestroy, OnInit, Output, ViewChild} from '../../src/core';
|
||||
|
|
|
@ -7,12 +7,12 @@
|
|||
*/
|
||||
|
||||
import {DEFAULT_CURRENCY_CODE, LOCALE_ID} from '@angular/core';
|
||||
import {inject} from '@angular/core/testing';
|
||||
import {ivyEnabled} from '@angular/private/testing';
|
||||
|
||||
import {getLocaleId} from '../src/render3';
|
||||
import {global} from '../src/util/global';
|
||||
import {TestBed} from '../testing';
|
||||
import {describe, expect, inject, it} from '../testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('Application module', () => {
|
||||
|
|
|
@ -9,8 +9,6 @@
|
|||
import {Injector, IterableDiffer, IterableDifferFactory, IterableDiffers, NgModule, TrackByFunction} from '@angular/core';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
|
||||
import {SpyIterableDifferFactory} from '../../spies';
|
||||
|
||||
{
|
||||
describe('IterableDiffers', function() {
|
||||
let factory1: any;
|
||||
|
@ -18,9 +16,10 @@ import {SpyIterableDifferFactory} from '../../spies';
|
|||
let factory3: any;
|
||||
|
||||
beforeEach(() => {
|
||||
factory1 = new SpyIterableDifferFactory();
|
||||
factory2 = new SpyIterableDifferFactory();
|
||||
factory3 = new SpyIterableDifferFactory();
|
||||
const getFactory = () => jasmine.createSpyObj('IterableDifferFactory', ['supports']);
|
||||
factory1 = getFactory();
|
||||
factory2 = getFactory();
|
||||
factory3 = getFactory();
|
||||
});
|
||||
|
||||
it('should throw when no suitable implementation found', () => {
|
||||
|
@ -30,17 +29,17 @@ import {SpyIterableDifferFactory} from '../../spies';
|
|||
});
|
||||
|
||||
it('should return the first suitable implementation', () => {
|
||||
factory1.spy('supports').and.returnValue(false);
|
||||
factory2.spy('supports').and.returnValue(true);
|
||||
factory3.spy('supports').and.returnValue(true);
|
||||
factory1.supports.and.returnValue(false);
|
||||
factory2.supports.and.returnValue(true);
|
||||
factory3.supports.and.returnValue(true);
|
||||
|
||||
const differs = IterableDiffers.create(<any>[factory1, factory2, factory3]);
|
||||
expect(differs.find('some object')).toBe(factory2);
|
||||
});
|
||||
|
||||
it('should copy over differs from the parent repo', () => {
|
||||
factory1.spy('supports').and.returnValue(true);
|
||||
factory2.spy('supports').and.returnValue(false);
|
||||
factory1.supports.and.returnValue(true);
|
||||
factory2.supports.and.returnValue(false);
|
||||
|
||||
const parent = IterableDiffers.create(<any>[factory1]);
|
||||
const child = IterableDiffers.create(<any>[factory2], parent);
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {Type} from '@angular/core';
|
||||
import {forwardRef, resolveForwardRef} from '@angular/core/src/di';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('forwardRef', function() {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
|
||||
import {Injector} from '@angular/core';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('Injector.NULL', () => {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {ɵgetDOM as getDOM} from '@angular/common';
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {isTextNode} from '@angular/platform-browser/testing/src/browser_util';
|
||||
|
||||
{
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
// This isn't used for anything, but for some reason Bazel won't
|
||||
// serve the file if there isn't at least one import.
|
||||
import '@angular/core/testing';
|
||||
|
||||
{
|
||||
describe('Shim', () => {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {filter} from 'rxjs/operators';
|
||||
|
||||
import {EventEmitter} from '../src/event_emitter';
|
||||
|
@ -19,51 +18,47 @@ import {EventEmitter} from '../src/event_emitter';
|
|||
emitter = new EventEmitter();
|
||||
});
|
||||
|
||||
it('should call the next callback',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call the next callback', done => {
|
||||
emitter.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual(99);
|
||||
async.done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
emitter.emit(99);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should call the throw callback',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call the throw callback', done => {
|
||||
emitter.subscribe({
|
||||
next: () => {},
|
||||
error: (error: any) => {
|
||||
expect(error).toEqual('Boom');
|
||||
async.done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
emitter.error('Boom');
|
||||
}));
|
||||
});
|
||||
|
||||
it('should work when no throw callback is provided',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should work when no throw callback is provided', done => {
|
||||
emitter.subscribe({
|
||||
next: () => {},
|
||||
error: (_: any) => {
|
||||
async.done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
emitter.error('Boom');
|
||||
}));
|
||||
});
|
||||
|
||||
it('should call the return callback',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call the return callback', done => {
|
||||
emitter.subscribe({
|
||||
next: () => {},
|
||||
error: (_: any) => {},
|
||||
complete: () => {
|
||||
async.done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
emitter.complete();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should subscribe to the wrapper synchronously', () => {
|
||||
let called = false;
|
||||
|
@ -77,8 +72,7 @@ import {EventEmitter} from '../src/event_emitter';
|
|||
expect(called).toBe(true);
|
||||
});
|
||||
|
||||
it('delivers next and error events synchronously',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('delivers next and error events synchronously', done => {
|
||||
const log: any[] /** TODO #9100 */ = [];
|
||||
|
||||
emitter.subscribe({
|
||||
|
@ -89,7 +83,7 @@ import {EventEmitter} from '../src/event_emitter';
|
|||
error: (err: any) => {
|
||||
log.push(err);
|
||||
expect(log).toEqual([1, 2, 3, 4]);
|
||||
async.done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
log.push(1);
|
||||
|
@ -97,7 +91,7 @@ import {EventEmitter} from '../src/event_emitter';
|
|||
log.push(3);
|
||||
emitter.error(4);
|
||||
log.push(5);
|
||||
}));
|
||||
});
|
||||
|
||||
it('delivers next and complete events synchronously', () => {
|
||||
const log: any[] /** TODO #9100 */ = [];
|
||||
|
@ -121,19 +115,18 @@ import {EventEmitter} from '../src/event_emitter';
|
|||
expect(log).toEqual([1, 2, 3, 4, 5]);
|
||||
});
|
||||
|
||||
it('delivers events asynchronously when forced to async mode',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('delivers events asynchronously when forced to async mode', done => {
|
||||
const e = new EventEmitter(true);
|
||||
const log: any[] /** TODO #9100 */ = [];
|
||||
e.subscribe((x: any) => {
|
||||
log.push(x);
|
||||
expect(log).toEqual([1, 3, 2]);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
log.push(1);
|
||||
e.emit(2);
|
||||
log.push(3);
|
||||
}));
|
||||
});
|
||||
|
||||
it('reports whether it has subscribers', () => {
|
||||
const e = new EventEmitter(false);
|
||||
|
@ -156,22 +149,18 @@ import {EventEmitter} from '../src/event_emitter';
|
|||
expect(emitter.observers.length).toBe(0);
|
||||
});
|
||||
|
||||
it('unsubscribing a subscriber invokes the dispose method', () => {
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('unsubscribing a subscriber invokes the dispose method', done => {
|
||||
const sub = emitter.subscribe();
|
||||
sub.add(() => async.done());
|
||||
sub.add(() => done());
|
||||
sub.unsubscribe();
|
||||
});
|
||||
});
|
||||
|
||||
it('unsubscribing a subscriber after applying operators with pipe() invokes the dispose method',
|
||||
() => {
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
const sub = emitter.pipe(filter(() => true)).subscribe();
|
||||
sub.add(() => async.done());
|
||||
sub.add(() => done());
|
||||
sub.unsubscribe();
|
||||
});
|
||||
});
|
||||
|
||||
it('error thrown inside an Rx chain propagates to the error handler and disposes the chain',
|
||||
() => {
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, tick} from '@angular/core/testing';
|
||||
import {beforeEach, describe, inject, it, Log} from '@angular/core/testing/src/testing_internal';
|
||||
import {discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, inject, tick} from '@angular/core/testing';
|
||||
import {Log} from '@angular/core/testing/src/testing_internal';
|
||||
import {EventManager} from '@angular/platform-browser';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {Component, Directive, HostBinding} from '@angular/core';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {modifiedInIvy, onlyInIvy} from '@angular/private/testing';
|
||||
|
||||
@Directive({selector: '[directiveA]'})
|
||||
|
|
|
@ -10,7 +10,6 @@ import {ɵgetDOM as getDOM} from '@angular/common';
|
|||
import {iterateListLike} from '@angular/core/src/change_detection/change_detection_util';
|
||||
import {QueryList} from '@angular/core/src/linker/query_list';
|
||||
import {fakeAsync, tick} from '@angular/core/testing';
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
{
|
||||
describe('QueryList', () => {
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import {Compiler, SystemJsNgModuleLoader} from '@angular/core';
|
||||
import {global} from '@angular/core/src/util/global';
|
||||
import {waitForAsync} from '@angular/core/testing';
|
||||
import {afterEach, beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {modifiedInIvy, onlyInIvy} from '@angular/private/testing';
|
||||
|
||||
function mockSystem(modules: {[module: string]: any}) {
|
||||
|
|
|
@ -12,7 +12,6 @@ import {i18nStartFirstCreatePass} from '@angular/core/src/render3/i18n/i18n_pars
|
|||
import {getTIcu} from '@angular/core/src/render3/i18n/i18n_util';
|
||||
import {I18nUpdateOpCodes, IcuType, TI18n} from '@angular/core/src/render3/interfaces/i18n';
|
||||
import {HEADER_OFFSET, HOST} from '@angular/core/src/render3/interfaces/view';
|
||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
||||
import {matchTI18n, matchTIcu} from '../matchers';
|
||||
import {matchDebug} from '../utils';
|
||||
import {ViewFixture} from '../view_fixture';
|
||||
|
|
|
@ -17,7 +17,6 @@ import {getNativeByIndex} from '@angular/core/src/render3/util/view_utils';
|
|||
import {keyValueArraySet} from '@angular/core/src/util/array_utils';
|
||||
import {ngDevModeResetPerfCounters} from '@angular/core/src/util/ng_dev_mode';
|
||||
import {getElementClasses, getElementStyles} from '@angular/core/testing/src/styling';
|
||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {clearFirstUpdatePass, enterViewWithOneDiv, rewindBindingIndex} from './shared_spec';
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import {AttributeMarker} from '@angular/core/src/render3';
|
||||
import {TAttributes} from '@angular/core/src/render3/interfaces/node';
|
||||
import {mergeHostAttribute, mergeHostAttrs} from '@angular/core/src/render3/util/attrs_utils';
|
||||
import {describe} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
describe('attr_util', () => {
|
||||
describe('mergeHostAttribute', () => {
|
||||
|
|
|
@ -6,16 +6,14 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import * as t from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer';
|
||||
|
||||
{
|
||||
t.describe('URL sanitizer', () => {
|
||||
describe('URL sanitizer', () => {
|
||||
let logMsgs: string[];
|
||||
let originalLog: (msg: any) => any;
|
||||
|
||||
t.beforeEach(() => {
|
||||
beforeEach(() => {
|
||||
logMsgs = [];
|
||||
originalLog = console.warn; // Monkey patch DOM.log.
|
||||
console.warn = (msg: any) => logMsgs.push(msg);
|
||||
|
@ -25,12 +23,12 @@ import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer
|
|||
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/);
|
||||
it('reports unsafe URLs', () => {
|
||||
expect(_sanitizeUrl('javascript:evil()')).toBe('unsafe:javascript:evil()');
|
||||
expect(logMsgs.join('\n')).toMatch(/sanitizing unsafe URL value/);
|
||||
});
|
||||
|
||||
t.describe('valid URLs', () => {
|
||||
describe('valid URLs', () => {
|
||||
const validUrls = [
|
||||
'',
|
||||
'http://abc',
|
||||
|
@ -51,11 +49,11 @@ import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer
|
|||
'data:audio/opus;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
|
||||
];
|
||||
for (const url of validUrls) {
|
||||
t.it(`valid ${url}`, () => t.expect(_sanitizeUrl(url)).toEqual(url));
|
||||
it(`valid ${url}`, () => expect(_sanitizeUrl(url)).toEqual(url));
|
||||
}
|
||||
});
|
||||
|
||||
t.describe('invalid URLs', () => {
|
||||
describe('invalid URLs', () => {
|
||||
const invalidUrls = [
|
||||
'javascript:evil()',
|
||||
'JavaScript:abc',
|
||||
|
@ -75,11 +73,11 @@ import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer
|
|||
'data:application/x-msdownload;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/',
|
||||
];
|
||||
for (const url of invalidUrls) {
|
||||
t.it(`valid ${url}`, () => t.expect(_sanitizeUrl(url)).toMatch(/^unsafe:/));
|
||||
it(`valid ${url}`, () => expect(_sanitizeUrl(url)).toMatch(/^unsafe:/));
|
||||
}
|
||||
});
|
||||
|
||||
t.describe('valid srcsets', () => {
|
||||
describe('valid srcsets', () => {
|
||||
const validSrcsets = [
|
||||
'',
|
||||
'http://angular.io/images/test.png',
|
||||
|
@ -102,17 +100,17 @@ import {_sanitizeUrl, sanitizeSrcset} from '../../src/sanitization/url_sanitizer
|
|||
'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));
|
||||
it(`valid ${srcset}`, () => expect(sanitizeSrcset(srcset)).toEqual(srcset));
|
||||
}
|
||||
});
|
||||
|
||||
t.describe('invalid srcsets', () => {
|
||||
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:/));
|
||||
it(`valid ${srcset}`, () => expect(sanitizeSrcset(srcset)).toMatch(/unsafe:/));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google LLC 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 {DomAdapter} from '@angular/common/src/dom_adapter';
|
||||
import {ElementRef} from '@angular/core';
|
||||
import {ChangeDetectorRef} from '@angular/core/src/change_detection/change_detection';
|
||||
import {SpyObject} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
export class SpyChangeDetectorRef extends SpyObject {
|
||||
constructor() {
|
||||
super(ChangeDetectorRef);
|
||||
this.spy('detectChanges');
|
||||
this.spy('checkNoChanges');
|
||||
}
|
||||
}
|
||||
|
||||
export class SpyIterableDifferFactory extends SpyObject {}
|
||||
|
||||
export class SpyElementRef extends SpyObject {
|
||||
constructor() {
|
||||
super(ElementRef);
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google LLC 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 {TestBed} from '@angular/core/testing/src/test_bed';
|
||||
import {AsyncTestCompleter, ddescribe, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
describe('TestBed with async processing', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.resetTestingModule();
|
||||
});
|
||||
|
||||
it('should allow injecting AsyncTestCompleter',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
async.done();
|
||||
}));
|
||||
});
|
|
@ -11,7 +11,6 @@ import {Injectable} from '@angular/core/src/di';
|
|||
import {PendingMacrotask, Testability, TestabilityRegistry} from '@angular/core/src/testability/testability';
|
||||
import {NgZone} from '@angular/core/src/zone/ng_zone';
|
||||
import {fakeAsync, flush, tick, waitForAsync} from '@angular/core/testing';
|
||||
import {beforeEach, describe, expect, it, SpyObject} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
import {scheduleMicroTask} from '../../src/util/microtask';
|
||||
|
||||
|
@ -58,9 +57,9 @@ class MockNgZone extends NgZone {
|
|||
beforeEach(waitForAsync(() => {
|
||||
ngZone = new MockNgZone();
|
||||
testability = new Testability(ngZone);
|
||||
execute = new SpyObject().spy('execute');
|
||||
execute2 = new SpyObject().spy('execute');
|
||||
updateCallback = new SpyObject().spy('execute');
|
||||
execute = jasmine.createSpy('execute');
|
||||
execute2 = jasmine.createSpy('execute');
|
||||
updateCallback = jasmine.createSpy('execute');
|
||||
}));
|
||||
|
||||
describe('Pending count logic', () => {
|
||||
|
|
|
@ -1,144 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google LLC 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 {SpyObject} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
class TestObj {
|
||||
prop: any;
|
||||
constructor(prop: any) {
|
||||
this.prop = prop;
|
||||
}
|
||||
someFunc(): number {
|
||||
return -1;
|
||||
}
|
||||
someComplexFunc(a: any) {
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
describe('testing', () => {
|
||||
describe('should respect custom equality tester', () => {
|
||||
beforeEach(() => {
|
||||
const equalIfMarried = (first: any, second: any) => {
|
||||
return first === 'kevin' && second === 'patricia';
|
||||
};
|
||||
jasmine.addCustomEqualityTester(equalIfMarried);
|
||||
});
|
||||
|
||||
it('for positive test', () => {
|
||||
expect('kevin').toEqual('patricia');
|
||||
});
|
||||
|
||||
it('for negative test', () => {
|
||||
expect('kevin').not.toEqual('kevin');
|
||||
});
|
||||
});
|
||||
|
||||
describe('equality', () => {
|
||||
it('should structurally compare objects', () => {
|
||||
const expected = new TestObj(new TestObj({'one': [1, 2]}));
|
||||
const actual = new TestObj(new TestObj({'one': [1, 2]}));
|
||||
const falseActual = new TestObj(new TestObj({'one': [1, 3]}));
|
||||
|
||||
expect(actual).toEqual(expected);
|
||||
expect(falseActual).not.toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toEqual for Maps', () => {
|
||||
it('should detect equality for same reference', () => {
|
||||
const m1: Map<string, number> = new Map();
|
||||
m1.set('a', 1);
|
||||
expect(m1).toEqual(m1);
|
||||
});
|
||||
|
||||
it('should detect equality for same content', () => {
|
||||
const m1: Map<string, number> = new Map();
|
||||
m1.set('a', 1);
|
||||
const m2: Map<string, number> = new Map();
|
||||
m2.set('a', 1);
|
||||
expect(m1).toEqual(m2);
|
||||
});
|
||||
|
||||
it('should detect missing entries', () => {
|
||||
const m1: Map<string, number> = new Map();
|
||||
m1.set('a', 1);
|
||||
const m2: Map<string, number> = new Map();
|
||||
expect(m1).not.toEqual(m2);
|
||||
});
|
||||
|
||||
it('should detect different values', () => {
|
||||
const m1: Map<string, number> = new Map();
|
||||
m1.set('a', 1);
|
||||
const m2: Map<string, number> = new Map();
|
||||
m2.set('a', 2);
|
||||
expect(m1).not.toEqual(m2);
|
||||
});
|
||||
|
||||
it('should detect additional entries', () => {
|
||||
const m1: Map<string, number> = new Map();
|
||||
m1.set('a', 1);
|
||||
const m2: Map<string, number> = new Map();
|
||||
m2.set('a', 1);
|
||||
m2.set('b', 2);
|
||||
expect(m1).not.toEqual(m2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('spy objects', () => {
|
||||
let spyObj: any;
|
||||
|
||||
beforeEach(() => {
|
||||
spyObj = new SpyObject(TestObj);
|
||||
});
|
||||
|
||||
it('should return a new spy func with no calls', () => {
|
||||
expect(spyObj.spy('someFunc')).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should record function calls', () => {
|
||||
spyObj.spy('someFunc').and.callFake((a: any, b: any) => a + b);
|
||||
|
||||
expect(spyObj.someFunc(1, 2)).toEqual(3);
|
||||
expect(spyObj.spy('someFunc')).toHaveBeenCalledWith(1, 2);
|
||||
});
|
||||
|
||||
it('should match multiple function calls', () => {
|
||||
spyObj.spy('someFunc');
|
||||
spyObj.someFunc(1, 2);
|
||||
spyObj.someFunc(3, 4);
|
||||
expect(spyObj.spy('someFunc')).toHaveBeenCalledWith(1, 2);
|
||||
expect(spyObj.spy('someFunc')).toHaveBeenCalledWith(3, 4);
|
||||
});
|
||||
|
||||
it('should match null arguments', () => {
|
||||
spyObj.spy('someFunc');
|
||||
spyObj.someFunc(null, 'hello');
|
||||
expect(spyObj.spy('someFunc')).toHaveBeenCalledWith(null, 'hello');
|
||||
});
|
||||
|
||||
it('should match using deep equality', () => {
|
||||
spyObj.spy('someComplexFunc');
|
||||
spyObj.someComplexFunc([1]);
|
||||
expect(spyObj.spy('someComplexFunc')).toHaveBeenCalledWith([1]);
|
||||
});
|
||||
|
||||
it('should support stubs', () => {
|
||||
const s = SpyObject.stub({'a': 1}, {'b': 2});
|
||||
expect(s.a()).toEqual(1);
|
||||
expect(s.b()).toEqual(2);
|
||||
});
|
||||
|
||||
it('should create spys for all methods', () => {
|
||||
spyObj.spy('someFunc');
|
||||
expect(() => spyObj.someFunc()).not.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
|
@ -7,8 +7,8 @@
|
|||
*/
|
||||
|
||||
import {EventEmitter, NgZone} from '@angular/core';
|
||||
import {fakeAsync, flushMicrotasks, waitForAsync} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it, Log, xit} from '@angular/core/testing/src/testing_internal';
|
||||
import {fakeAsync, flushMicrotasks, inject, waitForAsync} from '@angular/core/testing';
|
||||
import {Log} from '@angular/core/testing/src/testing_internal';
|
||||
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';
|
||||
|
||||
import {global} from '../../src/util/global';
|
||||
|
@ -18,7 +18,6 @@ import {NoopNgZone} from '../../src/zone/ng_zone';
|
|||
|
||||
const needsLongerTimers = browserDetection.isSlow || browserDetection.isEdge;
|
||||
const resultTimer = 1000;
|
||||
const testTimeout = browserDetection.isEdge ? 1200 : 500;
|
||||
// Schedules a macrotask (using a timer)
|
||||
function macroTask(fn: (...args: any[]) => void, timer = 1): void {
|
||||
// adds longer timers for passing tests in IE and Edge
|
||||
|
@ -88,8 +87,7 @@ function runNgZoneNoLog(fn: () => any) {
|
|||
|
||||
commonTests();
|
||||
|
||||
it('should produce long stack traces',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should produce long stack traces', done => {
|
||||
macroTask(() => {
|
||||
let resolve: (result: any) => void;
|
||||
const promise: Promise<any> = new Promise((res) => {
|
||||
|
@ -108,13 +106,12 @@ function runNgZoneNoLog(fn: () => any) {
|
|||
promise.then((_) => {
|
||||
expect(_traces.length).toBe(1);
|
||||
expect(_traces[0].length).toBeGreaterThan(1);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}), testTimeout);
|
||||
|
||||
it('should produce long stack traces (when using microtasks)',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should produce long stack traces (when using microtasks)', done => {
|
||||
macroTask(() => {
|
||||
let resolve: (result: any) => void;
|
||||
const promise: Promise<any> = new Promise((res) => {
|
||||
|
@ -133,10 +130,10 @@ function runNgZoneNoLog(fn: () => any) {
|
|||
promise.then((_) => {
|
||||
expect(_traces.length).toBe(1);
|
||||
expect(_traces[0].length).toBeGreaterThan(1);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
describe('short stack trace', () => {
|
||||
|
@ -150,8 +147,7 @@ function runNgZoneNoLog(fn: () => any) {
|
|||
|
||||
commonTests();
|
||||
|
||||
it('should disable long stack traces',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should disable long stack traces', done => {
|
||||
macroTask(() => {
|
||||
let resolve: (result: any) => void;
|
||||
const promise: Promise<any> = new Promise((res) => {
|
||||
|
@ -173,10 +169,10 @@ function runNgZoneNoLog(fn: () => any) {
|
|||
// some browsers don't have stack traces.
|
||||
expect(_traces[0].indexOf('---')).toEqual(-1);
|
||||
}
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}), testTimeout);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -287,43 +283,39 @@ function commonTests() {
|
|||
runNgZoneNoLog(() => {
|
||||
expect(NgZone.isInAngularZone()).toEqual(true);
|
||||
});
|
||||
}, testTimeout);
|
||||
});
|
||||
});
|
||||
|
||||
describe('run', () => {
|
||||
it('should return the body return value from run',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should return the body return value from run', done => {
|
||||
macroTask(() => {
|
||||
expect(_zone.run(() => 6)).toEqual(6);
|
||||
});
|
||||
|
||||
macroTask(() => {
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}), testTimeout);
|
||||
|
||||
it('should return the body return value from runTask',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should return the body return value from runTask', done => {
|
||||
macroTask(() => {
|
||||
expect(_zone.runTask(() => 6)).toEqual(6);
|
||||
});
|
||||
|
||||
macroTask(() => {
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}), testTimeout);
|
||||
|
||||
it('should call onUnstable and onMicrotaskEmpty',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call onUnstable and onMicrotaskEmpty', done => {
|
||||
runNgZoneNoLog(() => macroTask(_log.fn('run')));
|
||||
macroTask(() => {
|
||||
expect(_log.result()).toEqual('onUnstable; run; onMicrotaskEmpty; onStable');
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}), testTimeout);
|
||||
|
||||
it('should call onStable once at the end of event',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call onStable once at the end of event', done => {
|
||||
// The test is set up in a way that causes the zone loop to run onMicrotaskEmpty twice
|
||||
// then verified that onStable is only called once at the end
|
||||
|
||||
|
@ -348,22 +340,20 @@ function commonTests() {
|
|||
.toEqual(
|
||||
'onUnstable; run; onMicrotaskEmpty; onMicrotaskEmpty 1; ' +
|
||||
'onMicrotaskEmpty; onMicrotaskEmpty 2; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should call standalone onStable',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call standalone onStable', done => {
|
||||
runNgZoneNoLog(() => macroTask(_log.fn('run')));
|
||||
|
||||
macroTask(() => {
|
||||
expect(_log.result()).toEqual('onUnstable; run; onMicrotaskEmpty; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
xit('should run subscriber listeners in the subscription zone (outside)',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
xit('should run subscriber listeners in the subscription zone (outside)', done => {
|
||||
// Each subscriber fires a microtask outside the Angular zone. The test
|
||||
// then verifies that those microtasks do not cause additional digests.
|
||||
|
||||
|
@ -403,12 +393,11 @@ function commonTests() {
|
|||
|
||||
macroTask(() => {
|
||||
expect(_log.result()).toEqual('onUnstable; run; onMicrotaskEmpty; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should run subscriber listeners in the subscription zone (inside)',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should run subscriber listeners in the subscription zone (inside)', done => {
|
||||
runNgZoneNoLog(() => macroTask(_log.fn('run')));
|
||||
|
||||
// the only practical use-case to run a callback inside the zone is
|
||||
|
@ -430,12 +419,11 @@ function commonTests() {
|
|||
.toEqual(
|
||||
'onUnstable; run; onMicrotaskEmpty; onMyMicrotaskEmpty; ' +
|
||||
'onMicrotaskEmpty; onMyMicrotaskEmpty; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should run async tasks scheduled inside onStable outside Angular zone',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should run async tasks scheduled inside onStable outside Angular zone', done => {
|
||||
runNgZoneNoLog(() => macroTask(_log.fn('run')));
|
||||
|
||||
_zone.onStable.subscribe({
|
||||
|
@ -446,14 +434,13 @@ function commonTests() {
|
|||
});
|
||||
|
||||
macroTask(() => {
|
||||
expect(_log.result())
|
||||
.toEqual('onUnstable; run; onMicrotaskEmpty; onStable; onMyTaskDone');
|
||||
async.done();
|
||||
expect(_log.result()).toEqual('onUnstable; run; onMicrotaskEmpty; onStable; onMyTaskDone');
|
||||
done();
|
||||
});
|
||||
});
|
||||
}), testTimeout);
|
||||
|
||||
it('should call onUnstable once before a turn and onMicrotaskEmpty once after the turn',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
runNgZoneNoLog(() => {
|
||||
macroTask(() => {
|
||||
_log.add('run start');
|
||||
|
@ -466,12 +453,11 @@ function commonTests() {
|
|||
// The microtask (async) is executed after the macrotask (run)
|
||||
expect(_log.result())
|
||||
.toEqual('onUnstable; run start; run end; async; onMicrotaskEmpty; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should not run onUnstable and onMicrotaskEmpty for nested Zone.run',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should not run onUnstable and onMicrotaskEmpty for nested Zone.run', done => {
|
||||
runNgZoneNoLog(() => {
|
||||
macroTask(() => {
|
||||
_log.add('start run');
|
||||
|
@ -487,12 +473,12 @@ function commonTests() {
|
|||
expect(_log.result())
|
||||
.toEqual(
|
||||
'onUnstable; start run; nested run; end run; nested run microtask; onMicrotaskEmpty; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should not run onUnstable and onMicrotaskEmpty for nested Zone.run invoked from onMicrotaskEmpty',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
runNgZoneNoLog(() => macroTask(_log.fn('start run')));
|
||||
|
||||
_zone.onMicrotaskEmpty.subscribe({
|
||||
|
@ -507,12 +493,11 @@ function commonTests() {
|
|||
expect(_log.result())
|
||||
.toEqual(
|
||||
'onUnstable; start run; onMicrotaskEmpty; onMicrotaskEmpty:started; nested run; onMicrotaskEmpty:finished; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should call onUnstable and onMicrotaskEmpty before and after each top-level run',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call onUnstable and onMicrotaskEmpty before and after each top-level run', done => {
|
||||
runNgZoneNoLog(() => macroTask(_log.fn('run1')));
|
||||
runNgZoneNoLog(() => macroTask(_log.fn('run2')));
|
||||
|
||||
|
@ -520,12 +505,11 @@ function commonTests() {
|
|||
expect(_log.result())
|
||||
.toEqual(
|
||||
'onUnstable; run1; onMicrotaskEmpty; onStable; onUnstable; run2; onMicrotaskEmpty; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should call onUnstable and onMicrotaskEmpty before and after each turn',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call onUnstable and onMicrotaskEmpty before and after each turn', done => {
|
||||
let aResolve: (result: string) => void;
|
||||
let aPromise: Promise<string>;
|
||||
let bResolve: (result: string) => void;
|
||||
|
@ -557,24 +541,23 @@ function commonTests() {
|
|||
expect(_log.result())
|
||||
.toEqual(
|
||||
'onUnstable; run start; onMicrotaskEmpty; onStable; onUnstable; a then; b then; onMicrotaskEmpty; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should run a function outside of the angular zone',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should run a function outside of the angular zone', done => {
|
||||
macroTask(() => {
|
||||
_zone.runOutsideAngular(_log.fn('run'));
|
||||
});
|
||||
|
||||
macroTask(() => {
|
||||
expect(_log.result()).toEqual('run');
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}), testTimeout);
|
||||
|
||||
it('should call onUnstable and onMicrotaskEmpty when an inner microtask is scheduled from outside angular',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
let resolve: (result: string|null) => void;
|
||||
let promise: Promise<string|null>;
|
||||
|
||||
|
@ -608,13 +591,13 @@ function commonTests() {
|
|||
// Third VM Turn => execute the microtask (inside angular)
|
||||
// No onUnstable; because we don't own the task which started the turn.
|
||||
'executedMicrotask; onMicrotaskEmpty; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should call onUnstable only before executing a microtask scheduled in onMicrotaskEmpty ' +
|
||||
'and not onMicrotaskEmpty after executing the task',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
runNgZoneNoLog(() => macroTask(_log.fn('run')));
|
||||
|
||||
let ran = false;
|
||||
|
@ -642,13 +625,13 @@ function commonTests() {
|
|||
'onUnstable; run; onMicrotaskEmpty; onMicrotaskEmpty(begin); onMicrotaskEmpty(end); ' +
|
||||
// Second microtaskDrain Turn => microtask enqueued from onMicrotaskEmpty
|
||||
'executedMicrotask; onMicrotaskEmpty; onMicrotaskEmpty(begin); onMicrotaskEmpty(end); onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should call onUnstable and onMicrotaskEmpty for a scheduleMicroTask in onMicrotaskEmpty triggered by ' +
|
||||
'a scheduleMicroTask in run',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
runNgZoneNoLog(() => {
|
||||
macroTask(() => {
|
||||
_log.add('scheduleMicroTask');
|
||||
|
@ -680,12 +663,11 @@ function commonTests() {
|
|||
'onUnstable; scheduleMicroTask; run(executeMicrotask); onMicrotaskEmpty; onMicrotaskEmpty(begin); onMicrotaskEmpty(scheduleMicroTask); onMicrotaskEmpty(end); ' +
|
||||
// Second VM Turn => the microtask enqueued from onMicrotaskEmpty
|
||||
'onMicrotaskEmpty(executeMicrotask); onMicrotaskEmpty; onMicrotaskEmpty(begin); onMicrotaskEmpty(end); onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should execute promises scheduled in onUnstable before promises scheduled in run',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should execute promises scheduled in onUnstable before promises scheduled in run', done => {
|
||||
runNgZoneNoLog(() => {
|
||||
macroTask(() => {
|
||||
_log.add('run start');
|
||||
|
@ -744,12 +726,12 @@ function commonTests() {
|
|||
'onMicrotaskEmpty(begin); onMicrotaskEmpty(schedulePromise); onMicrotaskEmpty(end); ' +
|
||||
// Second VM turn: execute the microtask from onTurnEnd
|
||||
'onMicrotaskEmpty(executePromise); onMicrotaskEmpty; onMicrotaskEmpty(begin); onMicrotaskEmpty(end); onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should call onUnstable and onMicrotaskEmpty before and after each turn, respectively',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
let aResolve: (result: string|null) => void;
|
||||
let aPromise: Promise<string|null>;
|
||||
let bResolve: (result: string|null) => void;
|
||||
|
@ -790,12 +772,12 @@ function commonTests() {
|
|||
'onUnstable; a then; onMicrotaskEmpty; onStable; ' +
|
||||
// Third VM turn
|
||||
'onUnstable; b then; onMicrotaskEmpty; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should call onUnstable and onMicrotaskEmpty before and after (respectively) all turns in a chain',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
runNgZoneNoLog(() => {
|
||||
macroTask(() => {
|
||||
_log.add('run start');
|
||||
|
@ -811,12 +793,12 @@ function commonTests() {
|
|||
expect(_log.result())
|
||||
.toEqual(
|
||||
'onUnstable; run start; run end; async1; async2; onMicrotaskEmpty; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
|
||||
it('should call onUnstable and onMicrotaskEmpty for promises created outside of run body',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
let promise: Promise<any>;
|
||||
|
||||
runNgZoneNoLog(() => {
|
||||
|
@ -835,14 +817,13 @@ function commonTests() {
|
|||
.toEqual(
|
||||
'onUnstable; zone run; onMicrotaskEmpty; onStable; ' +
|
||||
'onUnstable; promise then; onMicrotaskEmpty; onStable');
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
});
|
||||
|
||||
describe('exceptions', () => {
|
||||
it('should call the on error callback when it is invoked via zone.runGuarded',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call the on error callback when it is invoked via zone.runGuarded', done => {
|
||||
macroTask(() => {
|
||||
const exception = new Error('sync');
|
||||
|
||||
|
@ -852,12 +833,12 @@ function commonTests() {
|
|||
|
||||
expect(_errors.length).toBe(1);
|
||||
expect(_errors[0]).toBe(exception);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}), testTimeout);
|
||||
|
||||
it('should not call the on error callback but rethrow when it is invoked via zone.run',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
macroTask(() => {
|
||||
const exception = new Error('sync');
|
||||
expect(() => _zone.run(() => {
|
||||
|
@ -865,12 +846,11 @@ function commonTests() {
|
|||
})).toThrowError('sync');
|
||||
|
||||
expect(_errors.length).toBe(0);
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}), testTimeout);
|
||||
|
||||
it('should call onError for errors from microtasks',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should call onError for errors from microtasks', done => {
|
||||
const exception = new Error('async');
|
||||
|
||||
macroTask(() => {
|
||||
|
@ -884,9 +864,9 @@ function commonTests() {
|
|||
macroTask(() => {
|
||||
expect(_errors.length).toBe(1);
|
||||
expect(_errors[0]).toEqual(exception);
|
||||
async.done();
|
||||
done();
|
||||
}, resultTimer);
|
||||
}), testTimeout);
|
||||
});
|
||||
});
|
||||
|
||||
describe('bugs', () => {
|
||||
|
@ -1009,7 +989,7 @@ function commonTests() {
|
|||
global.setImmediate = patchedImmediate;
|
||||
});
|
||||
|
||||
it('should run in requestAnimationFrame async', (done: DoneFn) => {
|
||||
it('should run in requestAnimationFrame async', done => {
|
||||
let task: Task|undefined = undefined;
|
||||
coalesceZone.run(() => {
|
||||
task = Zone.current.scheduleEventTask('myEvent', () => {
|
||||
|
@ -1025,7 +1005,7 @@ function commonTests() {
|
|||
});
|
||||
|
||||
it('should only emit onMicroTaskEmpty once within the same event loop for multiple event tasks',
|
||||
(done: DoneFn) => {
|
||||
done => {
|
||||
const tasks: Task[] = [];
|
||||
coalesceZone.run(() => {
|
||||
tasks.push(Zone.current.scheduleEventTask('myEvent', () => {
|
||||
|
@ -1045,7 +1025,7 @@ function commonTests() {
|
|||
});
|
||||
|
||||
it('should only emit onMicroTaskEmpty once within the same event loop for ngZone.run in onMicrotaskEmpty subscription',
|
||||
(done: DoneFn) => {
|
||||
done => {
|
||||
const tasks: Task[] = [];
|
||||
coalesceZone.onMicrotaskEmpty.subscribe(() => {
|
||||
coalesceZone.run(() => {});
|
||||
|
@ -1071,7 +1051,7 @@ function commonTests() {
|
|||
});
|
||||
|
||||
it('should emit onMicroTaskEmpty once within the same event loop for not only event tasks, but event tasks are before other tasks',
|
||||
(done: DoneFn) => {
|
||||
done => {
|
||||
const tasks: Task[] = [];
|
||||
coalesceZone.run(() => {
|
||||
tasks.push(Zone.current.scheduleEventTask('myEvent', () => {
|
||||
|
@ -1094,7 +1074,7 @@ function commonTests() {
|
|||
});
|
||||
|
||||
it('should emit multiple onMicroTaskEmpty within the same event loop for not only event tasks, but event tasks are after other tasks',
|
||||
(done: DoneFn) => {
|
||||
done => {
|
||||
const tasks: Task[] = [];
|
||||
coalesceZone.run(() => {
|
||||
tasks.push(Zone.current.scheduleMacroTask('myMacro', () => {
|
||||
|
@ -1148,7 +1128,7 @@ function commonTests() {
|
|||
global.setImmediate = patchedImmediate;
|
||||
});
|
||||
|
||||
it('should run in requestAnimationFrame async', (done: DoneFn) => {
|
||||
it('should run in requestAnimationFrame async', done => {
|
||||
coalesceZone.run(() => {});
|
||||
expect(logs).toEqual([]);
|
||||
nativeRequestAnimationFrame(() => {
|
||||
|
@ -1158,7 +1138,7 @@ function commonTests() {
|
|||
});
|
||||
|
||||
it('should only emit onMicroTaskEmpty once within the same event loop for multiple ngZone.run',
|
||||
(done: DoneFn) => {
|
||||
done => {
|
||||
coalesceZone.run(() => {});
|
||||
coalesceZone.run(() => {});
|
||||
expect(logs).toEqual([]);
|
||||
|
@ -1169,7 +1149,7 @@ function commonTests() {
|
|||
});
|
||||
|
||||
it('should only emit onMicroTaskEmpty once within the same event loop for ngZone.run in onMicrotaskEmpty subscription',
|
||||
(done: DoneFn) => {
|
||||
done => {
|
||||
coalesceZone.onMicrotaskEmpty.subscribe(() => {
|
||||
coalesceZone.run(() => {});
|
||||
});
|
||||
|
@ -1183,7 +1163,7 @@ function commonTests() {
|
|||
});
|
||||
|
||||
it('should only emit onMicroTaskEmpty once within the same event loop for multiple tasks',
|
||||
(done: DoneFn) => {
|
||||
done => {
|
||||
const tasks: Task[] = [];
|
||||
coalesceZone.run(() => {
|
||||
tasks.push(Zone.current.scheduleMacroTask('myMacro', () => {
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google LLC 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Injectable completer that allows signaling completion of an asynchronous test. Used internally.
|
||||
*/
|
||||
export class AsyncTestCompleter {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private _resolve!: (result: any) => void;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private _reject!: (err: any) => void;
|
||||
private _promise: Promise<any> = new Promise((res, rej) => {
|
||||
this._resolve = res;
|
||||
this._reject = rej;
|
||||
});
|
||||
done(value?: any) {
|
||||
this._resolve(value);
|
||||
}
|
||||
|
||||
fail(error?: any, stackTrace?: string) {
|
||||
this._reject(error);
|
||||
}
|
||||
|
||||
get promise(): Promise<any> {
|
||||
return this._promise;
|
||||
}
|
||||
}
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {ApplicationInitStatus, CompilerOptions, Component, Directive, InjectFlags, InjectionToken, Injector, NgModule, NgModuleFactory, NgModuleRef, NgZone, Optional, Pipe, PlatformRef, Provider, ProviderToken, SchemaMetadata, SkipSelf, StaticProvider, Type, ɵclearOverrides as clearOverrides, ɵDepFlags as DepFlags, ɵgetInjectableDef as getInjectableDef, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵivyEnabled as ivyEnabled, ɵNodeFlags as NodeFlags, ɵoverrideComponentView as overrideComponentView, ɵoverrideProvider as overrideProvider, ɵstringify as stringify, ɵɵInjectableDeclaration} from '@angular/core';
|
||||
|
||||
import {AsyncTestCompleter} from './async_test_completer';
|
||||
import {ComponentFixture} from './component_fixture';
|
||||
import {MetadataOverride} from './metadata_override';
|
||||
import {_getTestBedRender3, TestBedRender3} from './r3_test_bed';
|
||||
|
@ -660,32 +659,14 @@ function _getTestBedViewEngine(): TestBedViewEngine {
|
|||
* })
|
||||
* ```
|
||||
*
|
||||
* Notes:
|
||||
* - inject is currently a function because of some Traceur limitation the syntax should
|
||||
* eventually
|
||||
* becomes `it('...', @Inject (object: AClass, async: AsyncTestCompleter) => { ... });`
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export function inject(tokens: any[], fn: Function): () => any {
|
||||
const testBed = getTestBed();
|
||||
if (tokens.indexOf(AsyncTestCompleter) >= 0) {
|
||||
// Not using an arrow function to preserve context passed from call site
|
||||
return function(this: unknown) {
|
||||
// Return an async test method that returns a Promise if AsyncTestCompleter is one of
|
||||
// the injected tokens.
|
||||
return testBed.compileComponents().then(() => {
|
||||
const completer = testBed.inject(AsyncTestCompleter);
|
||||
testBed.execute(tokens, fn, this);
|
||||
return completer.promise;
|
||||
});
|
||||
};
|
||||
} else {
|
||||
// Not using an arrow function to preserve context passed from call site
|
||||
return function(this: unknown) {
|
||||
return testBed.execute(tokens, fn, this);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,213 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ɵisPromise as isPromise} from '@angular/core';
|
||||
import {global} from '@angular/core/src/util/global';
|
||||
|
||||
import {AsyncTestCompleter} from './async_test_completer';
|
||||
import {getTestBed, inject} from './test_bed';
|
||||
|
||||
export {AsyncTestCompleter} from './async_test_completer';
|
||||
export {inject} from './test_bed';
|
||||
|
||||
export * from './logger';
|
||||
export * from './ng_zone_mock';
|
||||
|
||||
export const proxy: ClassDecorator = (t: any) => t;
|
||||
|
||||
const _global = <any>(typeof window === 'undefined' ? global : window);
|
||||
|
||||
export const afterEach: Function = _global.afterEach;
|
||||
export const expect: <T>(actual: T) => jasmine.Matchers<T> = _global.expect;
|
||||
|
||||
const jsmBeforeEach = _global.beforeEach;
|
||||
const jsmDescribe = _global.describe;
|
||||
const jsmDDescribe = _global.fdescribe;
|
||||
const jsmXDescribe = _global.xdescribe;
|
||||
const jsmIt = _global.it;
|
||||
const jsmFIt = _global.fit;
|
||||
const jsmXIt = _global.xit;
|
||||
|
||||
const runnerStack: BeforeEachRunner[] = [];
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000;
|
||||
const globalTimeOut = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
|
||||
const testBed = getTestBed();
|
||||
|
||||
export type TestFn = ((done: DoneFn) => any)|(() => any);
|
||||
|
||||
/**
|
||||
* Mechanism to run `beforeEach()` functions of Angular tests.
|
||||
*
|
||||
* Note: Jasmine own `beforeEach` is used by this library to handle DI providers.
|
||||
*/
|
||||
class BeforeEachRunner {
|
||||
private _fns: Array<Function> = [];
|
||||
|
||||
constructor(private _parent: BeforeEachRunner) {}
|
||||
|
||||
beforeEach(fn: Function): void {
|
||||
this._fns.push(fn);
|
||||
}
|
||||
|
||||
run(): void {
|
||||
if (this._parent) this._parent.run();
|
||||
this._fns.forEach((fn) => {
|
||||
fn();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the test providers before each test
|
||||
jsmBeforeEach(() => {
|
||||
testBed.resetTestingModule();
|
||||
});
|
||||
|
||||
function _describe(jsmFn: Function, ...args: any[]) {
|
||||
const parentRunner = runnerStack.length === 0 ? null : runnerStack[runnerStack.length - 1];
|
||||
const runner = new BeforeEachRunner(parentRunner!);
|
||||
runnerStack.push(runner);
|
||||
const suite = jsmFn(...args);
|
||||
runnerStack.pop();
|
||||
return suite;
|
||||
}
|
||||
|
||||
export function describe(...args: any[]): void {
|
||||
return _describe(jsmDescribe, ...args);
|
||||
}
|
||||
|
||||
export function ddescribe(...args: any[]): void {
|
||||
return _describe(jsmDDescribe, ...args);
|
||||
}
|
||||
|
||||
export function xdescribe(...args: any[]): void {
|
||||
return _describe(jsmXDescribe, ...args);
|
||||
}
|
||||
|
||||
export function beforeEach(fn: Function): void {
|
||||
if (runnerStack.length > 0) {
|
||||
// Inside a describe block, beforeEach() uses a BeforeEachRunner
|
||||
runnerStack[runnerStack.length - 1].beforeEach(fn);
|
||||
} else {
|
||||
// Top level beforeEach() are delegated to jasmine
|
||||
jsmBeforeEach(fn);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows overriding default providers defined in test_injector.js.
|
||||
*
|
||||
* The given function must return a list of DI providers.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* beforeEachProviders(() => [
|
||||
* {provide: Compiler, useClass: MockCompiler},
|
||||
* {provide: SomeToken, useValue: myValue},
|
||||
* ]);
|
||||
*/
|
||||
export function beforeEachProviders(fn: Function): void {
|
||||
jsmBeforeEach(() => {
|
||||
const providers = fn();
|
||||
if (!providers) return;
|
||||
testBed.configureTestingModule({providers: providers});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function _it(jsmFn: Function, testName: string, testFn: TestFn, testTimeout = 0): void {
|
||||
if (runnerStack.length == 0) {
|
||||
// This left here intentionally, as we should never get here, and it aids debugging.
|
||||
// tslint:disable-next-line
|
||||
debugger;
|
||||
throw new Error('Empty Stack!');
|
||||
}
|
||||
const runner = runnerStack[runnerStack.length - 1];
|
||||
const timeout = Math.max(globalTimeOut, testTimeout);
|
||||
|
||||
jsmFn(testName, (done: DoneFn) => {
|
||||
const completerProvider = {
|
||||
provide: AsyncTestCompleter,
|
||||
useFactory: () => {
|
||||
// Mark the test as async when an AsyncTestCompleter is injected in an it()
|
||||
return new AsyncTestCompleter();
|
||||
}
|
||||
};
|
||||
testBed.configureTestingModule({providers: [completerProvider]});
|
||||
runner.run();
|
||||
|
||||
if (testFn.length === 0) {
|
||||
// TypeScript doesn't infer the TestFn type without parameters here, so we
|
||||
// need to manually cast it.
|
||||
const retVal = (testFn as () => any)();
|
||||
if (isPromise(retVal)) {
|
||||
// Asynchronous test function that returns a Promise - wait for completion.
|
||||
retVal.then(done, done.fail);
|
||||
} else {
|
||||
// Synchronous test function - complete immediately.
|
||||
done();
|
||||
}
|
||||
} else {
|
||||
// Asynchronous test function that takes in 'done' parameter.
|
||||
testFn(done);
|
||||
}
|
||||
}, timeout);
|
||||
}
|
||||
|
||||
export function it(expectation: string, assertion: TestFn, timeout?: number): void {
|
||||
return _it(jsmIt, expectation, assertion, timeout);
|
||||
}
|
||||
|
||||
export function fit(expectation: string, assertion: TestFn, timeout?: number): void {
|
||||
return _it(jsmFIt, expectation, assertion, timeout);
|
||||
}
|
||||
|
||||
export function xit(expectation: string, assertion: TestFn, timeout?: number): void {
|
||||
return _it(jsmXIt, expectation, assertion, timeout);
|
||||
}
|
||||
|
||||
export class SpyObject {
|
||||
constructor(type?: any) {
|
||||
if (type) {
|
||||
for (const prop in type.prototype) {
|
||||
let m: any = null;
|
||||
try {
|
||||
m = type.prototype[prop];
|
||||
} catch {
|
||||
// As we are creating spys for abstract classes,
|
||||
// these classes might have getters that throw when they are accessed.
|
||||
// As we are only auto creating spys for methods, this
|
||||
// should not matter.
|
||||
}
|
||||
if (typeof m === 'function') {
|
||||
this.spy(prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
spy(name: string) {
|
||||
if (!(this as any)[name]) {
|
||||
(this as any)[name] = jasmine.createSpy(name);
|
||||
}
|
||||
return (this as any)[name];
|
||||
}
|
||||
|
||||
prop(name: string, value: any) {
|
||||
(this as any)[name] = value;
|
||||
}
|
||||
|
||||
static stub(object: any = null, config: any = null, overrides: any = null) {
|
||||
if (!(object instanceof SpyObject)) {
|
||||
overrides = config;
|
||||
config = object;
|
||||
object = new SpyObject();
|
||||
}
|
||||
|
||||
const m = {...config, ...overrides};
|
||||
Object.keys(m).forEach(key => {
|
||||
object.spy(key).and.returnValue(m[key]);
|
||||
});
|
||||
return object;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,9 @@
|
|||
|
||||
import {SimpleChange} from '@angular/core';
|
||||
import {fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {AbstractControl, CheckboxControlValueAccessor, ControlValueAccessor, DefaultValueAccessor, FormArray, FormArrayName, FormControl, FormControlDirective, FormControlName, FormGroup, FormGroupDirective, FormGroupName, NgControl, NgForm, NgModel, NgModelGroup, SelectControlValueAccessor, SelectMultipleControlValueAccessor, ValidationErrors, Validator, Validators} from '@angular/forms';
|
||||
import {selectValueAccessor} from '@angular/forms/src/directives/shared';
|
||||
import {composeValidators} from '@angular/forms/src/validators';
|
||||
import {SpyNgControl, SpyValueAccessor} from './spies';
|
||||
import {asyncValidator} from './util';
|
||||
|
||||
class DummyControlValueAccessor implements ControlValueAccessor {
|
||||
|
@ -45,7 +43,7 @@ class CustomValidatorDirective implements Validator {
|
|||
let dir: NgControl;
|
||||
|
||||
beforeEach(() => {
|
||||
dir = <any>new SpyNgControl();
|
||||
dir = {path: []} as any;
|
||||
});
|
||||
|
||||
it('should throw when given an empty array', () => {
|
||||
|
@ -90,7 +88,7 @@ class CustomValidatorDirective implements Validator {
|
|||
});
|
||||
|
||||
it('should return custom accessor when provided', () => {
|
||||
const customAccessor: ControlValueAccessor = new SpyValueAccessor() as any;
|
||||
const customAccessor: ControlValueAccessor = {} as any;
|
||||
const checkboxAccessor = new CheckboxControlValueAccessor(null!, null!);
|
||||
expect(selectValueAccessor(dir, <any>[
|
||||
defaultAccessor, customAccessor, checkboxAccessor
|
||||
|
@ -98,7 +96,7 @@ class CustomValidatorDirective implements Validator {
|
|||
});
|
||||
|
||||
it('should return custom accessor when provided with select multiple', () => {
|
||||
const customAccessor: ControlValueAccessor = new SpyValueAccessor() as any;
|
||||
const customAccessor: ControlValueAccessor = {} as any;
|
||||
const selectMultipleAccessor = new SelectMultipleControlValueAccessor(null!, null!);
|
||||
expect(selectValueAccessor(dir, <any>[
|
||||
defaultAccessor, customAccessor, selectMultipleAccessor
|
||||
|
@ -106,7 +104,7 @@ class CustomValidatorDirective implements Validator {
|
|||
});
|
||||
|
||||
it('should throw when more than one custom accessor is provided', () => {
|
||||
const customAccessor: ControlValueAccessor = <any>new SpyValueAccessor();
|
||||
const customAccessor: ControlValueAccessor = {} as any;
|
||||
expect(() => selectValueAccessor(dir, [customAccessor, customAccessor])).toThrowError();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {fakeAsync, tick} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, ValidatorFn} from '@angular/forms';
|
||||
import {Validators} from '@angular/forms/src/validators';
|
||||
import {of} from 'rxjs';
|
||||
|
@ -856,20 +855,18 @@ describe('FormArray', () => {
|
|||
a = new FormArray([c1, c2]);
|
||||
});
|
||||
|
||||
it('should fire an event after the value has been updated',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should fire an event after the value has been updated', done => {
|
||||
a.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(a.value).toEqual(['new1', 'old2']);
|
||||
expect(value).toEqual(['new1', 'old2']);
|
||||
async.done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
c1.setValue('new1');
|
||||
}));
|
||||
});
|
||||
|
||||
it('should fire an event after the control\'s observable fired an event',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should fire an event after the control\'s observable fired an event', done => {
|
||||
let controlCallbackIsCalled = false;
|
||||
|
||||
|
||||
|
@ -882,38 +879,36 @@ describe('FormArray', () => {
|
|||
a.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(controlCallbackIsCalled).toBe(true);
|
||||
async.done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
c1.setValue('new1');
|
||||
}));
|
||||
});
|
||||
|
||||
it('should fire an event when a control is removed',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should fire an event when a control is removed', done => {
|
||||
a.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual(['old1']);
|
||||
async.done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
a.removeAt(1);
|
||||
}));
|
||||
});
|
||||
|
||||
it('should fire an event when a control is added',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should fire an event when a control is added', done => {
|
||||
a.removeAt(1);
|
||||
|
||||
a.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual(['old1', 'old2']);
|
||||
async.done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
a.push(c2);
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('get', () => {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {fakeAsync, tick} from '@angular/core/testing';
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {FormBuilder, Validators} from '@angular/forms';
|
||||
import {of} from 'rxjs';
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {fakeAsync, tick} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {FormControl, FormGroup, Validators} from '@angular/forms';
|
||||
|
||||
import {FormArray} from '@angular/forms/src/model';
|
||||
|
@ -857,17 +856,16 @@ describe('FormControl', () => {
|
|||
c = new FormControl('old', Validators.required);
|
||||
});
|
||||
|
||||
it('should fire an event after the value has been updated',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should fire an event after the value has been updated', done => {
|
||||
c.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(c.value).toEqual('new');
|
||||
expect(value).toEqual('new');
|
||||
async.done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
c.setValue('new');
|
||||
}));
|
||||
});
|
||||
|
||||
it('should fire an event after the status has been updated to invalid', fakeAsync(() => {
|
||||
c.statusChanges.subscribe({
|
||||
|
@ -911,27 +909,25 @@ describe('FormControl', () => {
|
|||
}));
|
||||
|
||||
// TODO: remove the if statement after making observable delivery sync
|
||||
it('should update set errors and status before emitting an event',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should update set errors and status before emitting an event', done => {
|
||||
c.valueChanges.subscribe((value: any /** TODO #9100 */) => {
|
||||
expect(c.valid).toEqual(false);
|
||||
expect(c.errors).toEqual({'required': true});
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
c.setValue('');
|
||||
}));
|
||||
});
|
||||
|
||||
it('should return a cold observable',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should return a cold observable', done => {
|
||||
c.setValue('will be ignored');
|
||||
c.valueChanges.subscribe({
|
||||
next: (value: any) => {
|
||||
expect(value).toEqual('new');
|
||||
async.done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
c.setValue('new');
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('setErrors', () => {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {fakeAsync, tick, waitForAsync} from '@angular/core/testing';
|
||||
import {AsyncTestCompleter, beforeEach, describe, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Validators} from '@angular/forms';
|
||||
import {of} from 'rxjs';
|
||||
|
||||
|
@ -822,8 +821,7 @@ describe('FormGroup', () => {
|
|||
|
||||
|
||||
// TODO(kara): update these tests to use fake Async
|
||||
it('should fire a statusChange if child has async validation change',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should fire a statusChange if child has async validation change', done => {
|
||||
const loggedValues: string[] = [];
|
||||
group.statusChanges.subscribe({
|
||||
next: (status: string) => {
|
||||
|
@ -831,11 +829,11 @@ describe('FormGroup', () => {
|
|||
if (loggedValues.length === 2) {
|
||||
expect(loggedValues).toEqual(['PENDING', 'INVALID']);
|
||||
}
|
||||
async.done();
|
||||
done();
|
||||
}
|
||||
});
|
||||
control.setValue('');
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
describe('getError', () => {
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
import {ɵgetDOM as getDOM} from '@angular/common';
|
||||
import {Component, Directive, forwardRef, Input, NgModule, OnDestroy, Type} from '@angular/core';
|
||||
import {ComponentFixture, fakeAsync, TestBed, tick} from '@angular/core/testing';
|
||||
import {expect} from '@angular/core/testing/src/testing_internal';
|
||||
import {AbstractControl, AsyncValidator, AsyncValidatorFn, COMPOSITION_BUFFER_MODE, ControlValueAccessor, DefaultValueAccessor, FormArray, FormControl, FormControlDirective, FormControlName, FormGroup, FormGroupDirective, FormsModule, MaxValidator, MinValidator, NG_ASYNC_VALIDATORS, NG_VALIDATORS, NG_VALUE_ACCESSOR, ReactiveFormsModule, Validator, Validators} from '@angular/forms';
|
||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||
import {dispatchEvent, sortedClassList} from '@angular/platform-browser/testing/src/browser_util';
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google LLC 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 {ChangeDetectorRef} from '@angular/core/src/change_detection/change_detector_ref';
|
||||
import {SpyObject} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
export class SpyChangeDetectorRef extends SpyObject {
|
||||
constructor() {
|
||||
super(ChangeDetectorRef);
|
||||
this.spy('markForCheck');
|
||||
}
|
||||
}
|
||||
|
||||
export class SpyNgControl extends SpyObject {
|
||||
path = [];
|
||||
}
|
||||
|
||||
export class SpyValueAccessor extends SpyObject {
|
||||
writeValue: any;
|
||||
}
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {fakeAsync, tick} from '@angular/core/testing';
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {AbstractControl, AsyncValidator, AsyncValidatorFn, FormArray, FormControl, ValidationErrors, ValidatorFn, Validators} from '@angular/forms';
|
||||
import {Observable, of, timer} from 'rxjs';
|
||||
import {first, map} from 'rxjs/operators';
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {ResourceLoaderImpl} from '@angular/platform-browser-dynamic/src/resource_loader/resource_loader_impl';
|
||||
|
||||
if (isBrowser) {
|
||||
|
@ -26,21 +25,19 @@ if (isBrowser) {
|
|||
resourceLoader = new ResourceLoaderImpl();
|
||||
});
|
||||
|
||||
it('should resolve the Promise with the file content on success',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should resolve the Promise with the file content on success', done => {
|
||||
resourceLoader.get(url200).then((text) => {
|
||||
expect(text.trim()).toEqual('<p>hey</p>');
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
}), 10000);
|
||||
}, 10000);
|
||||
|
||||
it('should reject the Promise on failure',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should reject the Promise on failure', done => {
|
||||
resourceLoader.get(url404).catch((e) => {
|
||||
expect(e).toEqual(`Failed to load ${url404}`);
|
||||
async.done();
|
||||
done();
|
||||
return null;
|
||||
});
|
||||
}), 10000);
|
||||
}, 10000);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -12,7 +12,8 @@ import {ApplicationRef, destroyPlatform} from '@angular/core/src/application_ref
|
|||
import {Console} from '@angular/core/src/console';
|
||||
import {ComponentRef} from '@angular/core/src/linker/component_factory';
|
||||
import {Testability, TestabilityRegistry} from '@angular/core/src/testability/testability';
|
||||
import {afterEach, AsyncTestCompleter, beforeEach, beforeEachProviders, describe, inject, it, Log} from '@angular/core/testing/src/testing_internal';
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import {Log} from '@angular/core/testing/src/testing_internal';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
@ -61,10 +62,6 @@ class HelloRootCmp4 {
|
|||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'hello-app'})
|
||||
class HelloRootMissingTemplate {
|
||||
}
|
||||
|
||||
@Directive({selector: 'hello-app'})
|
||||
class HelloRootDirectiveIsNotCmp {
|
||||
}
|
||||
|
@ -81,29 +78,6 @@ class HelloOnDestroyTickCmp implements OnDestroy {
|
|||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'hello-app', templateUrl: './sometemplate.html'})
|
||||
class HelloUrlCmp {
|
||||
greeting = 'hello';
|
||||
}
|
||||
|
||||
@Directive({selector: '[someDir]', host: {'[title]': 'someDir'}})
|
||||
class SomeDirective {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() someDir!: string;
|
||||
}
|
||||
|
||||
@Pipe({name: 'somePipe'})
|
||||
class SomePipe {
|
||||
transform(value: string): any {
|
||||
return `transformed ${value}`;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'hello-app', template: `<div [someDir]="'someValue' | somePipe"></div>`})
|
||||
class HelloCmpUsingPlatformDirectiveAndPipe {
|
||||
show: boolean = false;
|
||||
}
|
||||
|
||||
@Component({selector: 'hello-app', template: '<some-el [someProp]="true">hello world!</some-el>'})
|
||||
class HelloCmpUsingCustomElement {
|
||||
}
|
||||
|
@ -150,8 +124,8 @@ function bootstrap(
|
|||
if (isNode) return;
|
||||
let compilerConsole: DummyConsole;
|
||||
|
||||
beforeEachProviders(() => {
|
||||
return [Log];
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({providers: [Log]});
|
||||
});
|
||||
|
||||
beforeEach(inject([DOCUMENT], (doc: any) => {
|
||||
|
@ -175,10 +149,8 @@ function bootstrap(
|
|||
|
||||
afterEach(destroyPlatform);
|
||||
|
||||
// TODO(misko): can't use `modifiedInIvy.it` because the `it` is somehow special here.
|
||||
modifiedInIvy('bootstrapping non-Component throws in View Engine').isEnabled &&
|
||||
it('should throw if bootstrapped Directive is not a Component',
|
||||
inject([AsyncTestCompleter], (done: AsyncTestCompleter) => {
|
||||
modifiedInIvy('bootstrapping non-Component throws in View Engine')
|
||||
.it('should throw if bootstrapped Directive is not a Component', done => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
|
@ -186,13 +158,11 @@ function bootstrap(
|
|||
() => bootstrap(
|
||||
HelloRootDirectiveIsNotCmp, [{provide: ErrorHandler, useValue: errorHandler}]))
|
||||
.toThrowError(`HelloRootDirectiveIsNotCmp cannot be used as an entry component.`);
|
||||
done.done();
|
||||
}));
|
||||
done();
|
||||
});
|
||||
|
||||
// TODO(misko): can't use `onlyInIvy.it` because the `it` is somehow special here.
|
||||
onlyInIvy('bootstrapping non-Component rejects Promise in Ivy').isEnabled &&
|
||||
it('should throw if bootstrapped Directive is not a Component',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
onlyInIvy('bootstrapping non-Component rejects Promise in Ivy')
|
||||
.it('should throw if bootstrapped Directive is not a Component', done => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
|
@ -201,9 +171,9 @@ function bootstrap(
|
|||
]).catch((error: Error) => {
|
||||
expect(error).toEqual(
|
||||
new Error(`HelloRootDirectiveIsNotCmp cannot be used as an entry component.`));
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should retrieve sanitizer', inject([Injector], (injector: Injector) => {
|
||||
const sanitizer: Sanitizer|null = injector.get(Sanitizer, null);
|
||||
|
@ -218,22 +188,20 @@ function bootstrap(
|
|||
}
|
||||
}));
|
||||
|
||||
it('should throw if no element is found',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should throw if no element is found', done => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
bootstrap(NonExistentComp, [
|
||||
{provide: ErrorHandler, useValue: errorHandler}
|
||||
]).then(null, (reason) => {
|
||||
expect(reason.message)
|
||||
.toContain('The selector "non-existent" did not match any elements');
|
||||
async.done();
|
||||
expect(reason.message).toContain('The selector "non-existent" did not match any elements');
|
||||
done();
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
it('should throw if no provider', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should throw if no provider', done => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
|
@ -268,14 +236,13 @@ function bootstrap(
|
|||
' NullInjectorError: No provider for IDontExist!';
|
||||
}
|
||||
expect(e.message).toContain(errorMsg);
|
||||
async.done();
|
||||
done();
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
});
|
||||
|
||||
if (getDOM().supportsDOMEvents) {
|
||||
it('should forward the error to promise when bootstrap fails',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should forward the error to promise when bootstrap fails', done => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
|
@ -285,12 +252,11 @@ function bootstrap(
|
|||
refPromise.then(null, (reason: any) => {
|
||||
expect(reason.message)
|
||||
.toContain('The selector "non-existent" did not match any elements');
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should invoke the default exception handler when bootstrap fails',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should invoke the default exception handler when bootstrap fails', done => {
|
||||
const logger = new MockConsole();
|
||||
const errorHandler = new ErrorHandler();
|
||||
(errorHandler as any)._console = logger as any;
|
||||
|
@ -300,10 +266,10 @@ function bootstrap(
|
|||
refPromise.then(null, (reason) => {
|
||||
expect(logger.res[0].join('#'))
|
||||
.toContain('ERROR#Error: The selector "non-existent" did not match any elements');
|
||||
async.done();
|
||||
done();
|
||||
return null;
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
it('should create an injector promise', () => {
|
||||
|
@ -311,26 +277,25 @@ function bootstrap(
|
|||
expect(refPromise).toEqual(jasmine.any(Promise));
|
||||
});
|
||||
|
||||
it('should set platform name to browser',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should set platform name to browser', done => {
|
||||
const refPromise = bootstrap(HelloRootCmp, testProviders);
|
||||
refPromise.then((ref) => {
|
||||
expect(isPlatformBrowser(ref.injector.get(PLATFORM_ID))).toBe(true);
|
||||
async.done();
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should display hello world', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should display hello world', done => {
|
||||
const refPromise = bootstrap(HelloRootCmp, testProviders);
|
||||
refPromise.then((ref) => {
|
||||
expect(el).toHaveText('hello world!');
|
||||
expect(el.getAttribute('ng-version')).toEqual(VERSION.full);
|
||||
async.done();
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should throw a descriptive error if BrowserModule is installed again via a lazily loaded module',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
@NgModule({imports: [BrowserModule]})
|
||||
class AsyncModule {
|
||||
}
|
||||
|
@ -343,73 +308,69 @@ function bootstrap(
|
|||
`BrowserModule has already been loaded. If you need access to common directives such as NgIf and NgFor from a lazy loaded module, import CommonModule instead.`);
|
||||
});
|
||||
})
|
||||
.then(() => async.done(), err => async.fail(err));
|
||||
}));
|
||||
.then(() => done(), err => done.fail(err));
|
||||
});
|
||||
|
||||
it('should support multiple calls to bootstrap',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should support multiple calls to bootstrap', done => {
|
||||
const refPromise1 = bootstrap(HelloRootCmp, testProviders);
|
||||
const refPromise2 = bootstrap(HelloRootCmp2, testProviders);
|
||||
Promise.all([refPromise1, refPromise2]).then((refs) => {
|
||||
expect(el).toHaveText('hello world!');
|
||||
expect(el2).toHaveText('hello world, again!');
|
||||
async.done();
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not crash if change detection is invoked when the root component is disposed',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
bootstrap(HelloOnDestroyTickCmp, testProviders).then((ref) => {
|
||||
expect(() => ref.destroy()).not.toThrow();
|
||||
async.done();
|
||||
done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should unregister change detectors when components are disposed',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should unregister change detectors when components are disposed', done => {
|
||||
bootstrap(HelloRootCmp, testProviders).then((ref) => {
|
||||
const appRef = ref.injector.get(ApplicationRef);
|
||||
ref.destroy();
|
||||
expect(() => appRef.tick()).not.toThrow();
|
||||
async.done();
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should make the provided bindings available to the application component',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should make the provided bindings available to the application component', done => {
|
||||
const refPromise = bootstrap(
|
||||
HelloRootCmp3, [testProviders, {provide: 'appBinding', useValue: 'BoundValue'}]);
|
||||
|
||||
refPromise.then((ref) => {
|
||||
expect(ref.injector.get('appBinding')).toEqual('BoundValue');
|
||||
async.done();
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should not override locale provided during bootstrap',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should not override locale provided during bootstrap', done => {
|
||||
const refPromise =
|
||||
bootstrap(HelloRootCmp, [testProviders], [{provide: LOCALE_ID, useValue: 'fr-FR'}]);
|
||||
|
||||
refPromise.then(ref => {
|
||||
expect(ref.injector.get(LOCALE_ID)).toEqual('fr-FR');
|
||||
async.done();
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should avoid cyclic dependencies when root component requires Lifecycle through DI',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
const refPromise = bootstrap(HelloRootCmp4, testProviders);
|
||||
|
||||
refPromise.then((ref) => {
|
||||
const appRef = ref.injector.get(ApplicationRef);
|
||||
expect(appRef).toBeDefined();
|
||||
async.done();
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should run platform initializers',
|
||||
inject([Log, AsyncTestCompleter], (log: Log, async: AsyncTestCompleter) => {
|
||||
it('should run platform initializers', done => {
|
||||
inject([Log], (log: Log) => {
|
||||
const p = createPlatformFactory(platformBrowserDynamic, 'someName', [
|
||||
{provide: PLATFORM_INITIALIZER, useValue: log.fn('platform_init1'), multi: true},
|
||||
{provide: PLATFORM_INITIALIZER, useValue: log.fn('platform_init2'), multi: true}
|
||||
|
@ -430,12 +391,12 @@ function bootstrap(
|
|||
log.clear();
|
||||
p.bootstrapModule(SomeModule).then(() => {
|
||||
expect(log.result()).toEqual('app_init1; app_init2');
|
||||
async.done();
|
||||
done();
|
||||
}, done.fail);
|
||||
})();
|
||||
});
|
||||
}));
|
||||
|
||||
it('should remove styles when transitioning from a server render',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should remove styles when transitioning from a server render', done => {
|
||||
@Component({
|
||||
selector: 'root',
|
||||
template: 'root',
|
||||
|
@ -468,12 +429,11 @@ function bootstrap(
|
|||
styles.forEach(style => {
|
||||
expect(style.getAttribute('ng-transition')).not.toBe('my-app');
|
||||
});
|
||||
async.done();
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should register each application with the testability registry',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should register each application with the testability registry', done => {
|
||||
const refPromise1: Promise<ComponentRef<any>> = bootstrap(HelloRootCmp, testProviders);
|
||||
const refPromise2: Promise<ComponentRef<any>> = bootstrap(HelloRootCmp2, testProviders);
|
||||
|
||||
|
@ -481,20 +441,22 @@ function bootstrap(
|
|||
const registry = refs[0].injector.get(TestabilityRegistry);
|
||||
const testabilities =
|
||||
[refs[0].injector.get(Testability), refs[1].injector.get(Testability)];
|
||||
|
||||
Promise.all(testabilities).then((testabilities: Testability[]) => {
|
||||
expect(registry.findTestabilityInTree(el)).toEqual(testabilities[0]);
|
||||
expect(registry.findTestabilityInTree(el2)).toEqual(testabilities[1]);
|
||||
async.done();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
it('should allow to pass schemas', inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
bootstrap(HelloCmpUsingCustomElement, testProviders).then((compRef) => {
|
||||
expect(el).toHaveText('hello world!');
|
||||
async.done();
|
||||
done();
|
||||
}, done.fail);
|
||||
}, done.fail);
|
||||
});
|
||||
|
||||
it('should allow to pass schemas', done => {
|
||||
bootstrap(HelloCmpUsingCustomElement, testProviders).then(() => {
|
||||
expect(el).toHaveText('hello world!');
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
}));
|
||||
|
||||
describe('change detection', () => {
|
||||
const log: string[] = [];
|
||||
|
@ -529,7 +491,7 @@ function bootstrap(
|
|||
}
|
||||
|
||||
it('should be triggered for all bootstrapped components in case change happens in one of them',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
done => {
|
||||
@NgModule({
|
||||
imports: [BrowserModule],
|
||||
declarations: [CompA, CompB],
|
||||
|
@ -551,13 +513,12 @@ function bootstrap(
|
|||
expect(log).toContain('CompA:ngDoCheck');
|
||||
expect(log).toContain('CompB:ngDoCheck');
|
||||
|
||||
async.done();
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
}));
|
||||
|
||||
|
||||
it('should work in isolation for each component bootstrapped individually',
|
||||
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
|
||||
it('should work in isolation for each component bootstrapped individually', done => {
|
||||
const refPromise1 = bootstrap(CompA);
|
||||
const refPromise2 = bootstrap(CompB);
|
||||
Promise.all([refPromise1, refPromise2]).then((refs) => {
|
||||
|
@ -573,9 +534,9 @@ function bootstrap(
|
|||
expect(log).toContain('CompB:ngDoCheck');
|
||||
expect(log).not.toContain('CompA:ngDoCheck');
|
||||
|
||||
async.done();
|
||||
done();
|
||||
}, done.fail);
|
||||
});
|
||||
}));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
/**
|
||||
* @license
|
||||
* Copyright Google LLC 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 {Injector, ɵglobal as global} from '@angular/core';
|
||||
import {ApplicationRef} from '@angular/core/src/application_ref';
|
||||
import {SpyObject} from '@angular/core/testing/src/testing_internal';
|
||||
|
||||
export class SpyApplicationRef extends SpyObject {
|
||||
constructor() {
|
||||
super(ApplicationRef);
|
||||
}
|
||||
}
|
||||
|
||||
export class SpyComponentRef extends SpyObject {
|
||||
injector: any /** TODO #9100 */;
|
||||
constructor() {
|
||||
super();
|
||||
this.injector =
|
||||
Injector.create([{provide: ApplicationRef, useClass: SpyApplicationRef, deps: []}]);
|
||||
}
|
||||
}
|
||||
|
||||
export function callNgProfilerTimeChangeDetection(config?: any /** TODO #9100 */): void {
|
||||
(<any>global).ng.profiler.timeChangeDetection(config);
|
||||
}
|
|
@ -6,15 +6,22 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ApplicationRef, Injector, ɵglobal as global} from '@angular/core';
|
||||
import {disableDebugTools, enableDebugTools} from '@angular/platform-browser';
|
||||
|
||||
import {callNgProfilerTimeChangeDetection, SpyComponentRef} from './spies';
|
||||
|
||||
{
|
||||
describe('profiler', () => {
|
||||
if (isNode) return;
|
||||
|
||||
beforeEach(() => {
|
||||
enableDebugTools((<any>new SpyComponentRef()));
|
||||
enableDebugTools({
|
||||
injector: Injector.create([{
|
||||
provide: ApplicationRef,
|
||||
useValue: jasmine.createSpyObj(
|
||||
'ApplicationRef', ['bootstrap', 'tick', 'attachView', 'detachView']),
|
||||
deps: []
|
||||
}])
|
||||
} as any);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -30,3 +37,7 @@ import {callNgProfilerTimeChangeDetection, SpyComponentRef} from './spies';
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function callNgProfilerTimeChangeDetection(config?: any /** TODO #9100 */): void {
|
||||
(<any>global).ng.profiler.timeChangeDetection(config);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import {ɵgetDOM as getDOM} from '@angular/common';
|
||||
import {NgZone} from '@angular/core/src/zone/ng_zone';
|
||||
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {DomEventsPlugin} from '@angular/platform-browser/src/dom/events/dom_events';
|
||||
import {EventManager, EventManagerPlugin} from '@angular/platform-browser/src/dom/events/event_manager';
|
||||
import {createMouseEvent, el} from '../../../testing/src/browser_util';
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
import {NgZone} from '@angular/core';
|
||||
import {fakeAsync, inject, tick} from '@angular/core/testing';
|
||||
import {afterEach, beforeEach, describe, expect, it,} from '@angular/core/testing/src/testing_internal';
|
||||
import {EventManager} from '@angular/platform-browser';
|
||||
import {HammerGestureConfig, HammerGesturesPlugin,} from '@angular/platform-browser/src/dom/events/hammer_gestures';
|
||||
|
||||
|
@ -58,7 +57,7 @@ import {HammerGestureConfig, HammerGesturesPlugin,} from '@angular/platform-brow
|
|||
let originalHammerGlobal: any;
|
||||
|
||||
// Fake Hammer instance ("mc") used to test the underlying event registration.
|
||||
let fakeHammerInstance: {on: () => void, off: () => void};
|
||||
let fakeHammerInstance: {on: jasmine.Spy, off: jasmine.Spy};
|
||||
|
||||
// Inject the NgZone so that we can make it available to the plugin through a fake
|
||||
// EventManager.
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {describe, expect, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {KeyEventsPlugin} from '@angular/platform-browser/src/dom/events/key_events';
|
||||
|
||||
{
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import {ɵgetDOM as getDOM} from '@angular/common';
|
||||
import {beforeEach, describe, it} from '@angular/core/testing/src/testing_internal';
|
||||
import {DomSharedStylesHost} from '@angular/platform-browser/src/dom/shared_styles_host';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
|
||||
|
|
|
@ -7,15 +7,14 @@
|
|||
*/
|
||||
|
||||
import {SecurityContext} from '@angular/core';
|
||||
import * as t from '@angular/core/testing/src/testing_internal';
|
||||
import {DomSanitizerImpl} from '@angular/platform-browser/src/security/dom_sanitization_service';
|
||||
|
||||
{
|
||||
t.describe('DOM Sanitization Service', () => {
|
||||
t.it('accepts resource URL values for resource contexts', () => {
|
||||
describe('DOM Sanitization Service', () => {
|
||||
it('accepts resource URL values for resource contexts', () => {
|
||||
const svc = new DomSanitizerImpl(null);
|
||||
const resourceUrl = svc.bypassSecurityTrustResourceUrl('http://hello/world');
|
||||
t.expect(svc.sanitize(SecurityContext.URL, resourceUrl)).toBe('http://hello/world');
|
||||
expect(svc.sanitize(SecurityContext.URL, resourceUrl)).toBe('http://hello/world');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -335,9 +335,9 @@ const bTok = new InjectionToken<string>('b');
|
|||
});
|
||||
|
||||
describe('components with template url', () => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
beforeEach(waitForAsync(async () => {
|
||||
TestBed.configureTestingModule({declarations: [CompWithUrlTemplate]});
|
||||
TestBed.compileComponents();
|
||||
await TestBed.compileComponents();
|
||||
}));
|
||||
|
||||
isBrowser &&
|
||||
|
|
|
@ -10,7 +10,6 @@ import {CommonModule, Location} from '@angular/common';
|
|||
import {SpyLocation} from '@angular/common/testing';
|
||||
import {ChangeDetectionStrategy, Component, Injectable, NgModule, NgModuleFactoryLoader, NgModuleRef, NgZone, OnDestroy, ViewChild, ɵConsole as Console, ɵNoopNgZone as NoopNgZone} from '@angular/core';
|
||||
import {ComponentFixture, fakeAsync, inject, TestBed, tick} from '@angular/core/testing';
|
||||
import {describe} from '@angular/core/testing/src/testing_internal';
|
||||
import {By} from '@angular/platform-browser/src/dom/debug/by';
|
||||
import {expect} from '@angular/platform-browser/testing/src/matchers';
|
||||
import {ActivatedRoute, ActivatedRouteSnapshot, ActivationEnd, ActivationStart, CanActivate, CanDeactivate, ChildActivationEnd, ChildActivationStart, DefaultUrlSerializer, DetachedRouteHandle, Event, GuardsCheckEnd, GuardsCheckStart, Navigation, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, ParamMap, Params, PreloadAllModules, PreloadingStrategy, PRIMARY_OUTLET, Resolve, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, Router, RouteReuseStrategy, RouterEvent, RouterLink, RouterLinkWithHref, RouterModule, RouterPreloader, RouterStateSnapshot, RoutesRecognized, RunGuardsAndResolvers, UrlHandlingStrategy, UrlSegmentGroup, UrlSerializer, UrlTree} from '@angular/router';
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
// Tun on full stack traces in errors to help debugging
|
||||
Error.stackTraceLimit = Infinity;
|
||||
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000;
|
||||
|
||||
// Cancel Karma's synchronous start,
|
||||
// we will call `__karma__.start()` later, once all the specs are loaded.
|
||||
|
|
Loading…
Reference in New Issue