fix(zone.js): add issue numbers of `@types/jasmine` to the test cases (#34625)
Some cases will still need to use `spy as any` cast, because `@types/jasmine` have some issues, 1. The issue jasmine doesn't handle optional method properties, https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486 2. The issue jasmine doesn't handle overload method correctly, https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42455 PR Close #34625
This commit is contained in:
parent
ef4736d052
commit
41667de778
|
@ -29,8 +29,8 @@ const XSSI_PREFIX = ')]}\'\n';
|
|||
|
||||
{
|
||||
describe('XhrBackend', () => {
|
||||
let factory: MockXhrFactory = null !;
|
||||
let backend: HttpXhrBackend = null !;
|
||||
let factory: MockXhrFactory = null!;
|
||||
let backend: HttpXhrBackend = null!;
|
||||
beforeEach(() => {
|
||||
factory = new MockXhrFactory();
|
||||
backend = new HttpXhrBackend(factory);
|
||||
|
@ -92,7 +92,7 @@ const XSSI_PREFIX = ')]}\'\n';
|
|||
factory.mock.mockFlush(200, 'OK', JSON.stringify({data: 'some data'}));
|
||||
expect(events.length).toBe(2);
|
||||
const res = events[1] as HttpResponse<{data: string}>;
|
||||
expect(res.body !.data).toBe('some data');
|
||||
expect(res.body!.data).toBe('some data');
|
||||
});
|
||||
it('handles a blank json response', () => {
|
||||
const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'})));
|
||||
|
@ -106,14 +106,14 @@ const XSSI_PREFIX = ')]}\'\n';
|
|||
factory.mock.mockFlush(500, 'Error', JSON.stringify({data: 'some data'}));
|
||||
expect(events.length).toBe(2);
|
||||
const res = events[1] as any as HttpErrorResponse;
|
||||
expect(res.error !.data).toBe('some data');
|
||||
expect(res.error!.data).toBe('some data');
|
||||
});
|
||||
it('handles a json error response with XSSI prefix', () => {
|
||||
const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'})));
|
||||
factory.mock.mockFlush(500, 'Error', XSSI_PREFIX + JSON.stringify({data: 'some data'}));
|
||||
expect(events.length).toBe(2);
|
||||
const res = events[1] as any as HttpErrorResponse;
|
||||
expect(res.error !.data).toBe('some data');
|
||||
expect(res.error!.data).toBe('some data');
|
||||
});
|
||||
it('handles a json string response', () => {
|
||||
const events = trackEvents(backend.handle(TEST_POST.clone({responseType: 'json'})));
|
||||
|
@ -128,7 +128,7 @@ const XSSI_PREFIX = ')]}\'\n';
|
|||
factory.mock.mockFlush(200, 'OK', XSSI_PREFIX + JSON.stringify({data: 'some data'}));
|
||||
expect(events.length).toBe(2);
|
||||
const res = events[1] as HttpResponse<{data: string}>;
|
||||
expect(res.body !.data).toBe('some data');
|
||||
expect(res.body!.data).toBe('some data');
|
||||
});
|
||||
it('emits unsuccessful responses via the error path', done => {
|
||||
backend.handle(TEST_POST).subscribe(undefined, (err: HttpErrorResponse) => {
|
||||
|
|
|
@ -38,7 +38,7 @@ runInEachFileSystem(() => {
|
|||
initMockFileSystem(fs, testFiles);
|
||||
|
||||
// Force single-process execution in unit tests by mocking available CPUs to 1.
|
||||
spyOn(os, 'cpus').and.returnValue([{ model: 'Mock CPU' } as any]);
|
||||
spyOn(os, 'cpus').and.returnValue([{model: 'Mock CPU'} as any]);
|
||||
});
|
||||
|
||||
it('should run ngcc without errors for esm2015', () => {
|
||||
|
|
|
@ -13,6 +13,7 @@ describe('unlocker', () => {
|
|||
spyOn(process, 'on');
|
||||
require('../../../src/locking/lock_file_with_child_process/unlocker');
|
||||
// TODO: @JiaLiPassion, need to wait for @types/jasmine to handle the override case
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/42455
|
||||
expect(process.on).toHaveBeenCalledWith('disconnect' as any, jasmine.any(Function));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -47,7 +47,7 @@ describe('CachedFileSystem', () => {
|
|||
let lstatSpy: jasmine.Spy;
|
||||
beforeEach(() => {
|
||||
// For most of the tests the files are not symbolic links.
|
||||
lstatSpy = spyOn(delegate, 'lstat').and.returnValue({ isSymbolicLink: () => false } as any);
|
||||
lstatSpy = spyOn(delegate, 'lstat').and.returnValue({isSymbolicLink: () => false} as any);
|
||||
});
|
||||
|
||||
it('should call delegate if not in cache', () => {
|
||||
|
@ -93,7 +93,7 @@ describe('CachedFileSystem', () => {
|
|||
describe('invalidateCaches()', () => {
|
||||
it('should call the delegate `readFile()` if the path for the cached file has been invalidated',
|
||||
() => {
|
||||
spyOn(delegate, 'lstat').and.returnValue({ isSymbolicLink: () => false } as any);
|
||||
spyOn(delegate, 'lstat').and.returnValue({isSymbolicLink: () => false} as any);
|
||||
const spy = spyOn(delegate, 'readFile').and.returnValue('Some contents');
|
||||
fs.readFile(abcPath); // Call once to fill the cache
|
||||
spy.calls.reset();
|
||||
|
@ -230,7 +230,7 @@ describe('CachedFileSystem', () => {
|
|||
describe('moveFile()', () => {
|
||||
beforeEach(() => {
|
||||
// `moveFile()` relies upon `readFile` which calls through to `lstat()`, so stub it out.
|
||||
spyOn(delegate, 'lstat').and.returnValue({ isSymbolicLink: () => false } as any);
|
||||
spyOn(delegate, 'lstat').and.returnValue({isSymbolicLink: () => false} as any);
|
||||
});
|
||||
|
||||
it('should call delegate', () => {
|
||||
|
|
|
@ -69,6 +69,7 @@ describe('NodeJSFileSystem', () => {
|
|||
const result = fs.readdir(abcPath);
|
||||
expect(result).toEqual([relativeFrom('x'), relativeFrom('y/z')]);
|
||||
// TODO: @JiaLiPassion need to wait for @types/jasmine update to handle optional parameters.
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
|
||||
expect(spy as any).toHaveBeenCalledWith(abcPath);
|
||||
});
|
||||
});
|
||||
|
@ -90,6 +91,7 @@ describe('NodeJSFileSystem', () => {
|
|||
const result = fs.stat(abcPath);
|
||||
expect(result).toBe(stats);
|
||||
// TODO: @JiaLiPassion need to wait for @types/jasmine update to handle optional parameters.
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
|
||||
expect(spy as any).toHaveBeenCalledWith(abcPath);
|
||||
});
|
||||
});
|
||||
|
@ -173,12 +175,14 @@ describe('NodeJSFileSystem', () => {
|
|||
}
|
||||
return false;
|
||||
});
|
||||
spyOn(fs, 'stat').and.returnValue({ isDirectory: () => true } as any);
|
||||
const mkdirSyncSpy = spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
|
||||
if (path === abcPath) {
|
||||
throw new Error('It exists already. Supposedly.');
|
||||
}
|
||||
}) as any);
|
||||
spyOn(fs, 'stat').and.returnValue({isDirectory: () => true} as any);
|
||||
const mkdirSyncSpy =
|
||||
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
|
||||
if (path === abcPath) {
|
||||
throw new Error(
|
||||
'It exists already. Supposedly.');
|
||||
}
|
||||
}) as any);
|
||||
|
||||
fs.ensureDir(abcPath);
|
||||
expect(mkdirSyncSpy).toHaveBeenCalledTimes(3);
|
||||
|
@ -188,11 +192,12 @@ describe('NodeJSFileSystem', () => {
|
|||
|
||||
it('should fail if creating the directory throws and the directory does not exist', () => {
|
||||
spyOn(fs, 'exists').and.returnValue(false);
|
||||
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
|
||||
if (path === abcPath) {
|
||||
throw new Error('Unable to create directory (for whatever reason).');
|
||||
}
|
||||
}) as any);
|
||||
spyOn(realFs, 'mkdirSync')
|
||||
.and.callFake(((path: string) => {
|
||||
if (path === abcPath) {
|
||||
throw new Error('Unable to create directory (for whatever reason).');
|
||||
}
|
||||
}) as any);
|
||||
|
||||
expect(() => fs.ensureDir(abcPath))
|
||||
.toThrowError('Unable to create directory (for whatever reason).');
|
||||
|
@ -212,12 +217,12 @@ describe('NodeJSFileSystem', () => {
|
|||
}
|
||||
return false;
|
||||
});
|
||||
spyOn(fs, 'stat').and.returnValue({ isDirectory: isDirectorySpy } as any);
|
||||
spyOn(fs, 'stat').and.returnValue({isDirectory: isDirectorySpy} as any);
|
||||
spyOn(realFs, 'mkdirSync').and.callFake(((path: string) => {
|
||||
if (path === abcPath) {
|
||||
throw new Error('It exists already. Supposedly.');
|
||||
}
|
||||
}) as any);
|
||||
if (path === abcPath) {
|
||||
throw new Error('It exists already. Supposedly.');
|
||||
}
|
||||
}) as any);
|
||||
|
||||
expect(() => fs.ensureDir(abcPath)).toThrowError('It exists already. Supposedly.');
|
||||
expect(isDirectorySpy).toHaveBeenCalledTimes(1);
|
||||
|
|
|
@ -41,7 +41,9 @@ describe('ngc transformer command-line', () => {
|
|||
basePath = support.basePath;
|
||||
outDir = path.join(basePath, 'built');
|
||||
process.chdir(basePath);
|
||||
write = (fileName: string, content: string) => { support.write(fileName, content); };
|
||||
write = (fileName: string, content: string) => {
|
||||
support.write(fileName, content);
|
||||
};
|
||||
|
||||
write('tsconfig-base.json', `{
|
||||
"compilerOptions": {
|
||||
|
@ -96,8 +98,9 @@ describe('ngc transformer command-line', () => {
|
|||
});
|
||||
|
||||
describe('errors', () => {
|
||||
|
||||
beforeEach(() => { errorSpy.and.stub(); });
|
||||
beforeEach(() => {
|
||||
errorSpy.and.stub();
|
||||
});
|
||||
|
||||
it('should not print the stack trace if user input file does not exist', () => {
|
||||
writeConfig(`{
|
||||
|
@ -231,7 +234,6 @@ describe('ngc transformer command-line', () => {
|
|||
});
|
||||
|
||||
describe('compile ngfactory files', () => {
|
||||
|
||||
it('should compile ngfactory files that are not referenced by root files', () => {
|
||||
writeConfig(`{
|
||||
"extends": "./tsconfig-base.json",
|
||||
|
@ -1122,7 +1124,6 @@ describe('ngc transformer command-line', () => {
|
|||
});
|
||||
|
||||
describe('with external symbol re-exports enabled', () => {
|
||||
|
||||
it('should be able to compile multiple libraries with summaries', () => {
|
||||
// Note: we need to emit the generated code for the libraries
|
||||
// into the node_modules, as that is the only way that we
|
||||
|
@ -1560,11 +1561,13 @@ describe('ngc transformer command-line', () => {
|
|||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
|
||||
const timerToken = 100;
|
||||
// TODO: @JiaLiPassion, need to wait @types/jasmine to handle optional method case
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
|
||||
spyOn(ts.sys as any, 'setTimeout').and.callFake((callback: () => void) => {
|
||||
timer = callback;
|
||||
return timerToken;
|
||||
});
|
||||
// TODO: @JiaLiPassion, need to wait @types/jasmine to handle optional method case
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
|
||||
spyOn(ts.sys as any, 'clearTimeout').and.callFake((token: number) => {
|
||||
if (token == timerToken) {
|
||||
timer = undefined;
|
||||
|
@ -1617,7 +1620,9 @@ describe('ngc transformer command-line', () => {
|
|||
`);
|
||||
});
|
||||
|
||||
afterEach(() => { jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout; });
|
||||
afterEach(() => {
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||
});
|
||||
|
||||
function writeAppConfig(location: string) {
|
||||
writeConfig(`{
|
||||
|
@ -1672,11 +1677,13 @@ describe('ngc transformer command-line', () => {
|
|||
`);
|
||||
}));
|
||||
|
||||
it('should recompile when the html file changes',
|
||||
expectRecompile(() => { write('greet.html', '<p> Hello {{name}} again!</p>'); }));
|
||||
it('should recompile when the html file changes', expectRecompile(() => {
|
||||
write('greet.html', '<p> Hello {{name}} again!</p>');
|
||||
}));
|
||||
|
||||
it('should recompile when the css file changes',
|
||||
expectRecompile(() => { write('greet.css', `p.greeting { color: blue }`); }));
|
||||
it('should recompile when the css file changes', expectRecompile(() => {
|
||||
write('greet.css', `p.greeting { color: blue }`);
|
||||
}));
|
||||
});
|
||||
|
||||
describe('regressions', () => {
|
||||
|
@ -2041,8 +2048,8 @@ describe('ngc transformer command-line', () => {
|
|||
expect(exitCode).toBe(1, 'Compile was expected to fail');
|
||||
const srcPathWithSep = `lib/`;
|
||||
expect(messages[0])
|
||||
.toEqual(
|
||||
`${srcPathWithSep}test.component.ts(6,21): Error during template compile of 'TestComponent'
|
||||
.toEqual(`${
|
||||
srcPathWithSep}test.component.ts(6,21): Error during template compile of 'TestComponent'
|
||||
Tagged template expressions are not supported in metadata in 't1'
|
||||
't1' references 't2' at ${srcPathWithSep}indirect1.ts(3,27)
|
||||
't2' contains the error at ${srcPathWithSep}indirect2.ts(4,27).
|
||||
|
@ -2051,7 +2058,6 @@ describe('ngc transformer command-line', () => {
|
|||
});
|
||||
|
||||
describe('tree shakeable services', () => {
|
||||
|
||||
function compileService(source: string): string {
|
||||
write('service.ts', source);
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ describe('convertValueToOutputAst', () => {
|
|||
it('should convert all array elements, including undefined', () => {
|
||||
const ctx = null;
|
||||
const value = new Array(3).concat('foo');
|
||||
const expr = convertValueToOutputAst(ctx !, value) as o.LiteralArrayExpr;
|
||||
expect(expr instanceof o.LiteralArrayExpr);
|
||||
const expr = convertValueToOutputAst(ctx!, value) as o.LiteralArrayExpr;
|
||||
expect(expr instanceof o.LiteralArrayExpr).toBe(true);
|
||||
expect(expr.entries.length).toBe(4);
|
||||
for (let i = 0; i < 4; ++i) {
|
||||
expect(expr.entries[i] instanceof o.Expression).toBe(true);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -25,26 +25,41 @@ describe('global utils', () => {
|
|||
describe('publishDefaultGlobalUtils', () => {
|
||||
beforeEach(() => publishDefaultGlobalUtils());
|
||||
|
||||
it('should publish getComponent', () => { assertPublished('getComponent', getComponent); });
|
||||
it('should publish getComponent', () => {
|
||||
assertPublished('getComponent', getComponent);
|
||||
});
|
||||
|
||||
it('should publish getContext', () => { assertPublished('getContext', getContext); });
|
||||
it('should publish getContext', () => {
|
||||
assertPublished('getContext', getContext);
|
||||
});
|
||||
|
||||
it('should publish getListeners', () => { assertPublished('getListeners', getListeners); });
|
||||
it('should publish getListeners', () => {
|
||||
assertPublished('getListeners', getListeners);
|
||||
});
|
||||
|
||||
it('should publish getOwningComponent',
|
||||
() => { assertPublished('getOwningComponent', getOwningComponent); });
|
||||
it('should publish getOwningComponent', () => {
|
||||
assertPublished('getOwningComponent', getOwningComponent);
|
||||
});
|
||||
|
||||
it('should publish getRootComponents',
|
||||
() => { assertPublished('getRootComponents', getRootComponents); });
|
||||
it('should publish getRootComponents', () => {
|
||||
assertPublished('getRootComponents', getRootComponents);
|
||||
});
|
||||
|
||||
it('should publish getDirectives', () => { assertPublished('getDirectives', getDirectives); });
|
||||
it('should publish getDirectives', () => {
|
||||
assertPublished('getDirectives', getDirectives);
|
||||
});
|
||||
|
||||
it('should publish getHostComponent',
|
||||
() => { assertPublished('getHostElement', getHostElement); });
|
||||
it('should publish getHostComponent', () => {
|
||||
assertPublished('getHostElement', getHostElement);
|
||||
});
|
||||
|
||||
it('should publish getInjector', () => { assertPublished('getInjector', getInjector); });
|
||||
it('should publish getInjector', () => {
|
||||
assertPublished('getInjector', getInjector);
|
||||
});
|
||||
|
||||
it('should publish applyChanges', () => { assertPublished('applyChanges', applyChanges); });
|
||||
it('should publish applyChanges', () => {
|
||||
assertPublished('applyChanges', applyChanges);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -12,24 +12,21 @@ import {AttributeMarker, TAttributes, TNode, TNodeType} from '../../src/render3/
|
|||
import {CssSelector, CssSelectorList, SelectorFlags} from '../../src/render3/interfaces/projection';
|
||||
import {extractAttrsAndClassesFromSelector, getProjectAsAttrValue, isNodeMatchingSelector, isNodeMatchingSelectorList, stringifyCSSSelectorList} from '../../src/render3/node_selector_matcher';
|
||||
|
||||
function testLStaticData(tagName: string, attrs: TAttributes | null): TNode {
|
||||
return createTNode(null !, null, TNodeType.Element, 0, tagName, attrs);
|
||||
function testLStaticData(tagName: string, attrs: TAttributes|null): TNode {
|
||||
return createTNode(null!, null, TNodeType.Element, 0, tagName, attrs);
|
||||
}
|
||||
|
||||
describe('css selector matching', () => {
|
||||
function isMatching(
|
||||
tagName: string, attrsOrTNode: TAttributes | TNode | null, selector: CssSelector): boolean {
|
||||
tagName: string, attrsOrTNode: TAttributes|TNode|null, selector: CssSelector): boolean {
|
||||
const tNode = (!attrsOrTNode || Array.isArray(attrsOrTNode)) ?
|
||||
createTNode(null !, null, TNodeType.Element, 0, tagName, attrsOrTNode as TAttributes) :
|
||||
createTNode(null!, null, TNodeType.Element, 0, tagName, attrsOrTNode as TAttributes) :
|
||||
(attrsOrTNode as TNode);
|
||||
return isNodeMatchingSelector(tNode, selector, true);
|
||||
}
|
||||
|
||||
describe('isNodeMatchingSimpleSelector', () => {
|
||||
|
||||
|
||||
describe('element matching', () => {
|
||||
|
||||
it('should match element name only if names are the same', () => {
|
||||
expect(isMatching('span', null, ['span']))
|
||||
.toBeTruthy(`Selector 'span' should match <span>`);
|
||||
|
@ -55,11 +52,9 @@ describe('css selector matching', () => {
|
|||
});
|
||||
|
||||
describe('attributes matching', () => {
|
||||
|
||||
// TODO: do we need to differentiate no value and empty value? that is: title vs. title="" ?
|
||||
|
||||
it('should match single attribute without value', () => {
|
||||
|
||||
expect(isMatching('span', ['title', ''], [
|
||||
'', 'title', ''
|
||||
])).toBeTruthy(`Selector '[title]' should match <span title>`);
|
||||
|
@ -81,7 +76,8 @@ describe('css selector matching', () => {
|
|||
])).toBeFalsy(`Selector '[other]' should NOT match <span title="">'`);
|
||||
});
|
||||
|
||||
// TODO: Not sure how to fix this cases.
|
||||
// TODO: this case will not work, need more discussion
|
||||
// https://github.com/angular/angular/pull/34625#discussion_r401791275
|
||||
xit('should match namespaced attributes', () => {
|
||||
expect(isMatching(
|
||||
'span', [AttributeMarker.NamespaceURI, 'http://some/uri', 'title', 'name'],
|
||||
|
@ -228,7 +224,6 @@ describe('css selector matching', () => {
|
|||
});
|
||||
|
||||
describe('class matching', () => {
|
||||
|
||||
it('should match with a class selector when an element has multiple classes', () => {
|
||||
expect(isMatching('span', ['class', 'foo bar'], [
|
||||
'', SelectorFlags.CLASS, 'foo'
|
||||
|
@ -328,7 +323,6 @@ describe('css selector matching', () => {
|
|||
});
|
||||
|
||||
describe('negations', () => {
|
||||
|
||||
it('should match when negation part is null', () => {
|
||||
expect(isMatching('span', null, ['span'])).toBeTruthy(`Selector 'span' should match <span>`);
|
||||
});
|
||||
|
@ -436,13 +430,11 @@ describe('css selector matching', () => {
|
|||
expect(isMatching('div', ['name', 'name', 'title', '', 'class', 'foo bar'], selector))
|
||||
.toBeFalsy();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('isNodeMatchingSelectorList', () => {
|
||||
|
||||
function isAnyMatching(
|
||||
tagName: string, attrs: string[] | null, selector: CssSelectorList): boolean {
|
||||
tagName: string, attrs: string[]|null, selector: CssSelectorList): boolean {
|
||||
return isNodeMatchingSelectorList(testLStaticData(tagName, attrs), selector, false);
|
||||
}
|
||||
|
||||
|
@ -468,16 +460,18 @@ describe('css selector matching', () => {
|
|||
});
|
||||
|
||||
describe('reading the ngProjectAs attribute value', function() {
|
||||
|
||||
function testTNode(attrs: TAttributes | null) { return testLStaticData('tag', attrs); }
|
||||
function testTNode(attrs: TAttributes|null) {
|
||||
return testLStaticData('tag', attrs);
|
||||
}
|
||||
|
||||
it('should get ngProjectAs value if present', function() {
|
||||
expect(getProjectAsAttrValue(testTNode([AttributeMarker.ProjectAs, ['tag', 'foo', 'bar']])))
|
||||
.toEqual(['tag', 'foo', 'bar']);
|
||||
});
|
||||
|
||||
it('should return null if there are no attributes',
|
||||
function() { expect(getProjectAsAttrValue(testTNode(null))).toBe(null); });
|
||||
it('should return null if there are no attributes', function() {
|
||||
expect(getProjectAsAttrValue(testTNode(null))).toBe(null);
|
||||
});
|
||||
|
||||
it('should return if ngProjectAs is not present', function() {
|
||||
expect(getProjectAsAttrValue(testTNode(['foo', 'bar']))).toBe(null);
|
||||
|
@ -486,15 +480,13 @@ describe('css selector matching', () => {
|
|||
it('should not accidentally identify ngProjectAs in attribute values', function() {
|
||||
expect(getProjectAsAttrValue(testTNode(['foo', AttributeMarker.ProjectAs]))).toBe(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('stringifyCSSSelectorList', () => {
|
||||
|
||||
it('should stringify selector with a tag name only',
|
||||
() => { expect(stringifyCSSSelectorList([['button']])).toBe('button'); });
|
||||
it('should stringify selector with a tag name only', () => {
|
||||
expect(stringifyCSSSelectorList([['button']])).toBe('button');
|
||||
});
|
||||
|
||||
it('should stringify selector with attributes', () => {
|
||||
expect(stringifyCSSSelectorList([['', 'id', '']])).toBe('[id]');
|
||||
|
|
|
@ -17,6 +17,7 @@ describe('utils', () => {
|
|||
beforeEach(() => {
|
||||
// TODO: @JiaLiPassion, need to wait @types/jasmine to fix the wrong return
|
||||
// type infer issue.
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/43486
|
||||
setTimeoutSpy = spyOn(window, 'setTimeout').and.returnValue(42 as any);
|
||||
clearTimeoutSpy = spyOn(window, 'clearTimeout');
|
||||
});
|
||||
|
@ -83,8 +84,9 @@ describe('utils', () => {
|
|||
expect(camelToDashCase('foo1Bar2Baz3Qux4')).toBe('foo1-bar2-baz3-qux4');
|
||||
});
|
||||
|
||||
it('should keep existing dashes',
|
||||
() => { expect(camelToDashCase('fooBar-baz-Qux')).toBe('foo-bar-baz--qux'); });
|
||||
it('should keep existing dashes', () => {
|
||||
expect(camelToDashCase('fooBar-baz-Qux')).toBe('foo-bar-baz--qux');
|
||||
});
|
||||
});
|
||||
|
||||
describe('createCustomEvent()', () => {
|
||||
|
@ -99,7 +101,6 @@ describe('utils', () => {
|
|||
expect(event.cancelable).toBe(false);
|
||||
expect(event.detail).toEqual(value);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('isElement()', () => {
|
||||
|
@ -131,7 +132,7 @@ describe('utils', () => {
|
|||
it('should return true for functions', () => {
|
||||
const obj = {foo: function() {}, bar: () => null, baz() {}};
|
||||
const fns = [
|
||||
function(){},
|
||||
function() {},
|
||||
() => null,
|
||||
obj.foo,
|
||||
obj.bar,
|
||||
|
@ -182,7 +183,7 @@ describe('utils', () => {
|
|||
</ul>
|
||||
</div>
|
||||
`;
|
||||
li = div.querySelector('li') !;
|
||||
li = div.querySelector('li')!;
|
||||
});
|
||||
|
||||
it('should return whether the element matches the selector', () => {
|
||||
|
@ -218,7 +219,9 @@ describe('utils', () => {
|
|||
];
|
||||
|
||||
values.forEach((v1, i) => {
|
||||
values.forEach((v2, j) => { expect(strictEquals(v1, v2)).toBe(i === j); });
|
||||
values.forEach((v2, j) => {
|
||||
expect(strictEquals(v1, v2)).toBe(i === j);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Inject, ReflectiveInjector, forwardRef, resolveForwardRef} from '@angular/core';
|
||||
import {forwardRef, Inject, ReflectiveInjector, resolveForwardRef} from '@angular/core';
|
||||
|
||||
{
|
||||
describe('forwardRef examples', () => {
|
||||
|
@ -26,7 +26,9 @@ import {Inject, ReflectiveInjector, forwardRef, resolveForwardRef} from '@angula
|
|||
|
||||
// Door attempts to inject Lock, despite it not being defined yet.
|
||||
// forwardRef makes this possible.
|
||||
constructor(@Inject(forwardRef(() => Lock)) lock: Lock) { this.lock = lock; }
|
||||
constructor(@Inject(forwardRef(() => Lock)) lock: Lock) {
|
||||
this.lock = lock;
|
||||
}
|
||||
}
|
||||
|
||||
// Only at this point Lock is defined.
|
||||
|
|
|
@ -17,7 +17,9 @@ import {HammerGestureConfig, HammerGesturesPlugin,} from '@angular/platform-brow
|
|||
let fakeConsole: any;
|
||||
if (isNode) return;
|
||||
|
||||
beforeEach(() => { fakeConsole = {warn: jasmine.createSpy('console.warn')}; });
|
||||
beforeEach(() => {
|
||||
fakeConsole = {warn: jasmine.createSpy('console.warn')};
|
||||
});
|
||||
|
||||
describe('with no custom loader', () => {
|
||||
beforeEach(() => {
|
||||
|
@ -61,7 +63,9 @@ import {HammerGestureConfig, HammerGesturesPlugin,} from '@angular/platform-brow
|
|||
// Inject the NgZone so that we can make it available to the plugin through a fake
|
||||
// EventManager.
|
||||
let ngZone: NgZone;
|
||||
beforeEach(inject([NgZone], (z: NgZone) => { ngZone = z; }));
|
||||
beforeEach(inject([NgZone], (z: NgZone) => {
|
||||
ngZone = z;
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
originalHammerGlobal = (window as any).Hammer;
|
||||
|
@ -84,13 +88,15 @@ import {HammerGestureConfig, HammerGesturesPlugin,} from '@angular/platform-brow
|
|||
plugin = new HammerGesturesPlugin(document, hammerConfig, fakeConsole, loader);
|
||||
|
||||
// Use a fake EventManager that has access to the NgZone.
|
||||
plugin.manager = { getZone: () => ngZone } as EventManager;
|
||||
plugin.manager = {getZone: () => ngZone} as EventManager;
|
||||
|
||||
someElement = document.createElement('div');
|
||||
someListener = () => {};
|
||||
});
|
||||
|
||||
afterEach(() => { (window as any).Hammer = originalHammerGlobal; });
|
||||
afterEach(() => {
|
||||
(window as any).Hammer = originalHammerGlobal;
|
||||
});
|
||||
|
||||
it('should not log a warning when HammerJS is not loaded', () => {
|
||||
plugin.addEventListener(someElement, 'swipe', () => {});
|
||||
|
|
|
@ -51,7 +51,6 @@ import {KeyEventsPlugin} from '@angular/platform-browser/src/dom/events/key_even
|
|||
.toEqual({'domEventName': 'keydown', 'fullKey': 'control.shift'});
|
||||
expect(KeyEventsPlugin.parseEventName('keyup.control.shift'))
|
||||
.toEqual({'domEventName': 'keyup', 'fullKey': 'control.shift'});
|
||||
|
||||
});
|
||||
|
||||
it('should alias esc to escape', () => {
|
||||
|
@ -67,6 +66,5 @@ import {KeyEventsPlugin} from '@angular/platform-browser/src/dom/events/key_even
|
|||
expect(() => plugin.addGlobalEventListener('window', 'keyup.control.esc', () => {}))
|
||||
.not.toThrowError();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3708,8 +3708,7 @@ describe('Integration', () => {
|
|||
router.navigate(['/user/:fedor']);
|
||||
advance(fixture);
|
||||
|
||||
expect(navigateSpy.calls.mostRecent().args[1] !.queryParams);
|
||||
|
||||
expect(navigateSpy.calls.mostRecent().args[1]!.queryParams);
|
||||
})));
|
||||
});
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import {PLATFORM_ID} from '@angular/core';
|
||||
import {TestBed} from '@angular/core/testing';
|
||||
import {NgswCommChannel} from '@angular/service-worker/src/low_level';
|
||||
import {SwRegistrationOptions, ngswCommChannelFactory} from '@angular/service-worker/src/module';
|
||||
import {ngswCommChannelFactory, SwRegistrationOptions} from '@angular/service-worker/src/module';
|
||||
import {SwPush} from '@angular/service-worker/src/push';
|
||||
import {SwUpdate} from '@angular/service-worker/src/update';
|
||||
import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockServiceWorkerRegistration, patchDecodeBase64} from '@angular/service-worker/testing/mock';
|
||||
|
@ -32,14 +32,18 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
|
||||
mock.setupSw();
|
||||
|
||||
(comm as any).registration.subscribe((reg: any) => { done(); });
|
||||
(comm as any).registration.subscribe((reg: any) => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('can access the registration when it comes after subscription', done => {
|
||||
const mock = new MockServiceWorkerContainer();
|
||||
const comm = new NgswCommChannel(mock as any);
|
||||
const regPromise = mock.getRegistration() as any as MockServiceWorkerRegistration;
|
||||
|
||||
(comm as any).registration.subscribe((reg: any) => { done(); });
|
||||
(comm as any).registration.subscribe((reg: any) => {
|
||||
done();
|
||||
});
|
||||
|
||||
mock.setupSw();
|
||||
});
|
||||
|
@ -158,7 +162,7 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
});
|
||||
|
||||
describe('requestSubscription()', () => {
|
||||
it('returns a promise that resolves to the subscription', async() => {
|
||||
it('returns a promise that resolves to the subscription', async () => {
|
||||
const promise = push.requestSubscription({serverPublicKey: 'test'});
|
||||
expect(promise).toEqual(jasmine.any(Promise));
|
||||
|
||||
|
@ -166,7 +170,7 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
expect(sub).toEqual(jasmine.any(MockPushSubscription));
|
||||
});
|
||||
|
||||
it('calls `PushManager.subscribe()` (with appropriate options)', async() => {
|
||||
it('calls `PushManager.subscribe()` (with appropriate options)', async () => {
|
||||
const decode = (charCodeArr: Uint8Array) =>
|
||||
Array.from(charCodeArr).map(c => String.fromCharCode(c)).join('');
|
||||
|
||||
|
@ -183,12 +187,12 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
userVisibleOnly: true,
|
||||
});
|
||||
|
||||
const actualAppServerKey = pmSubscribeSpy.calls.first().args[0] !.applicationServerKey;
|
||||
const actualAppServerKey = pmSubscribeSpy.calls.first().args[0]!.applicationServerKey;
|
||||
const actualAppServerKeyStr = decode(actualAppServerKey as Uint8Array);
|
||||
expect(actualAppServerKeyStr).toBe(appServerKeyStr);
|
||||
});
|
||||
|
||||
it('emits the new `PushSubscription` on `SwPush.subscription`', async() => {
|
||||
it('emits the new `PushSubscription` on `SwPush.subscription`', async () => {
|
||||
const subscriptionSpy = jasmine.createSpy('subscriptionSpy');
|
||||
push.subscription.subscribe(subscriptionSpy);
|
||||
const sub = await push.requestSubscription({serverPublicKey: 'test'});
|
||||
|
@ -204,7 +208,7 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
psUnsubscribeSpy = spyOn(MockPushSubscription.prototype, 'unsubscribe').and.callThrough();
|
||||
});
|
||||
|
||||
it('rejects if currently not subscribed to push notifications', async() => {
|
||||
it('rejects if currently not subscribed to push notifications', async () => {
|
||||
try {
|
||||
await push.unsubscribe();
|
||||
throw new Error('`unsubscribe()` should fail');
|
||||
|
@ -213,15 +217,17 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
}
|
||||
});
|
||||
|
||||
it('calls `PushSubscription.unsubscribe()`', async() => {
|
||||
it('calls `PushSubscription.unsubscribe()`', async () => {
|
||||
await push.requestSubscription({serverPublicKey: 'test'});
|
||||
await push.unsubscribe();
|
||||
|
||||
expect(psUnsubscribeSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('rejects if `PushSubscription.unsubscribe()` fails', async() => {
|
||||
psUnsubscribeSpy.and.callFake(() => { throw new Error('foo'); });
|
||||
it('rejects if `PushSubscription.unsubscribe()` fails', async () => {
|
||||
psUnsubscribeSpy.and.callFake(() => {
|
||||
throw new Error('foo');
|
||||
});
|
||||
|
||||
try {
|
||||
await push.requestSubscription({serverPublicKey: 'test'});
|
||||
|
@ -232,7 +238,7 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
}
|
||||
});
|
||||
|
||||
it('rejects if `PushSubscription.unsubscribe()` returns false', async() => {
|
||||
it('rejects if `PushSubscription.unsubscribe()` returns false', async () => {
|
||||
psUnsubscribeSpy.and.returnValue(Promise.resolve(false));
|
||||
|
||||
try {
|
||||
|
@ -244,7 +250,7 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
}
|
||||
});
|
||||
|
||||
it('emits `null` on `SwPush.subscription`', async() => {
|
||||
it('emits `null` on `SwPush.subscription`', async () => {
|
||||
const subscriptionSpy = jasmine.createSpy('subscriptionSpy');
|
||||
push.subscription.subscribe(subscriptionSpy);
|
||||
|
||||
|
@ -254,7 +260,7 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
expect(subscriptionSpy).toHaveBeenCalledWith(null);
|
||||
});
|
||||
|
||||
it('does not emit on `SwPush.subscription` on failure', async() => {
|
||||
it('does not emit on `SwPush.subscription` on failure', async () => {
|
||||
const subscriptionSpy = jasmine.createSpy('subscriptionSpy');
|
||||
const initialSubEmit = new Promise(resolve => subscriptionSpy.and.callFake(resolve));
|
||||
|
||||
|
@ -271,7 +277,9 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
subscriptionSpy.calls.reset();
|
||||
|
||||
// Error due to `PushSubscription.unsubscribe()` error.
|
||||
psUnsubscribeSpy.and.callFake(() => { throw new Error('foo'); });
|
||||
psUnsubscribeSpy.and.callFake(() => {
|
||||
throw new Error('foo');
|
||||
});
|
||||
await push.unsubscribe().catch(() => undefined);
|
||||
expect(subscriptionSpy).not.toHaveBeenCalled();
|
||||
|
||||
|
@ -338,7 +346,7 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
push.subscription.subscribe(subscriptionSpy);
|
||||
});
|
||||
|
||||
it('emits on worker-driven changes (i.e. when the controller changes)', async() => {
|
||||
it('emits on worker-driven changes (i.e. when the controller changes)', async () => {
|
||||
// Initial emit for the current `ServiceWorkerController`.
|
||||
await nextSubEmitPromise;
|
||||
expect(subscriptionSpy).toHaveBeenCalledTimes(1);
|
||||
|
@ -353,7 +361,7 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
expect(subscriptionSpy).toHaveBeenCalledWith(null);
|
||||
});
|
||||
|
||||
it('emits on subscription changes (i.e. when subscribing/unsubscribing)', async() => {
|
||||
it('emits on subscription changes (i.e. when subscribing/unsubscribing)', async () => {
|
||||
await nextSubEmitPromise;
|
||||
subscriptionSpy.calls.reset();
|
||||
|
||||
|
@ -391,11 +399,16 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
});
|
||||
|
||||
it('gives an error when registering', done => {
|
||||
push.requestSubscription({serverPublicKey: 'test'}).catch(err => { done(); });
|
||||
push.requestSubscription({serverPublicKey: 'test'}).catch(err => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('gives an error when unsubscribing',
|
||||
done => { push.unsubscribe().catch(err => { done(); }); });
|
||||
it('gives an error when unsubscribing', done => {
|
||||
push.unsubscribe().catch(err => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -461,7 +474,9 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
});
|
||||
});
|
||||
return update.activateUpdate()
|
||||
.catch(err => { expect(err.message).toEqual('Failed to activate'); })
|
||||
.catch(err => {
|
||||
expect(err.message).toEqual('Failed to activate');
|
||||
})
|
||||
.then(() => done())
|
||||
.catch(err => done.fail(err));
|
||||
});
|
||||
|
@ -475,8 +490,12 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
expect(() => TestBed.inject(SwUpdate)).not.toThrow();
|
||||
});
|
||||
describe('with no SW', () => {
|
||||
beforeEach(() => { comm = new NgswCommChannel(undefined); });
|
||||
it('can be instantiated', () => { update = new SwUpdate(comm); });
|
||||
beforeEach(() => {
|
||||
comm = new NgswCommChannel(undefined);
|
||||
});
|
||||
it('can be instantiated', () => {
|
||||
update = new SwUpdate(comm);
|
||||
});
|
||||
it('does not crash on subscription to observables', () => {
|
||||
update = new SwUpdate(comm);
|
||||
update.available.toPromise().catch(err => fail(err));
|
||||
|
@ -484,11 +503,15 @@ import {MockPushManager, MockPushSubscription, MockServiceWorkerContainer, MockS
|
|||
});
|
||||
it('gives an error when checking for updates', done => {
|
||||
update = new SwUpdate(comm);
|
||||
update.checkForUpdate().catch(err => { done(); });
|
||||
update.checkForUpdate().catch(err => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('gives an error when activating updates', done => {
|
||||
update = new SwUpdate(comm);
|
||||
update.activateUpdate().catch(err => { done(); });
|
||||
update.activateUpdate().catch(err => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
*/
|
||||
|
||||
import {ApplicationRef, PLATFORM_ID} from '@angular/core';
|
||||
import {TestBed, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
||||
import {fakeAsync, flushMicrotasks, TestBed, tick} from '@angular/core/testing';
|
||||
import {Subject} from 'rxjs';
|
||||
import {filter, take} from 'rxjs/operators';
|
||||
|
||||
|
@ -33,7 +33,7 @@ describe('ServiceWorkerModule', () => {
|
|||
spyOn(navigator.serviceWorker, 'register').and.returnValue(Promise.resolve(null as any)));
|
||||
|
||||
describe('register()', () => {
|
||||
const configTestBed = async(opts: SwRegistrationOptions) => {
|
||||
const configTestBed = async (opts: SwRegistrationOptions) => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ServiceWorkerModule.register('sw.js', opts)],
|
||||
providers: [{provide: PLATFORM_ID, useValue: 'browser'}],
|
||||
|
@ -42,35 +42,35 @@ describe('ServiceWorkerModule', () => {
|
|||
await untilStable();
|
||||
};
|
||||
|
||||
it('sets the registration options', async() => {
|
||||
it('sets the registration options', async () => {
|
||||
await configTestBed({enabled: true, scope: 'foo'});
|
||||
|
||||
expect(TestBed.inject(SwRegistrationOptions)).toEqual({enabled: true, scope: 'foo'});
|
||||
expect(swRegisterSpy).toHaveBeenCalledWith('sw.js', {scope: 'foo'});
|
||||
});
|
||||
|
||||
it('can disable the SW', async() => {
|
||||
it('can disable the SW', async () => {
|
||||
await configTestBed({enabled: false});
|
||||
|
||||
expect(TestBed.inject(SwUpdate).isEnabled).toBe(false);
|
||||
expect(swRegisterSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('can enable the SW', async() => {
|
||||
it('can enable the SW', async () => {
|
||||
await configTestBed({enabled: true});
|
||||
|
||||
expect(TestBed.inject(SwUpdate).isEnabled).toBe(true);
|
||||
expect(swRegisterSpy).toHaveBeenCalledWith('sw.js', {scope: undefined});
|
||||
});
|
||||
|
||||
it('defaults to enabling the SW', async() => {
|
||||
it('defaults to enabling the SW', async () => {
|
||||
await configTestBed({});
|
||||
|
||||
expect(TestBed.inject(SwUpdate).isEnabled).toBe(true);
|
||||
expect(swRegisterSpy).toHaveBeenCalledWith('sw.js', {scope: undefined});
|
||||
});
|
||||
|
||||
it('catches and a logs registration errors', async() => {
|
||||
it('catches and a logs registration errors', async () => {
|
||||
const consoleErrorSpy = spyOn(console, 'error');
|
||||
swRegisterSpy.and.returnValue(Promise.reject('no reason'));
|
||||
|
||||
|
@ -92,7 +92,7 @@ describe('ServiceWorkerModule', () => {
|
|||
});
|
||||
};
|
||||
|
||||
it('sets the registration options (and overwrites those set via `.register()`', async() => {
|
||||
it('sets the registration options (and overwrites those set via `.register()`', async () => {
|
||||
configTestBed({enabled: true, scope: 'provider'});
|
||||
await untilStable();
|
||||
|
||||
|
@ -100,7 +100,7 @@ describe('ServiceWorkerModule', () => {
|
|||
expect(swRegisterSpy).toHaveBeenCalledWith('sw.js', {scope: 'provider'});
|
||||
});
|
||||
|
||||
it('can disable the SW', async() => {
|
||||
it('can disable the SW', async () => {
|
||||
configTestBed({enabled: false}, {enabled: true});
|
||||
await untilStable();
|
||||
|
||||
|
@ -108,7 +108,7 @@ describe('ServiceWorkerModule', () => {
|
|||
expect(swRegisterSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('can enable the SW', async() => {
|
||||
it('can enable the SW', async () => {
|
||||
configTestBed({enabled: true}, {enabled: false});
|
||||
await untilStable();
|
||||
|
||||
|
@ -116,7 +116,7 @@ describe('ServiceWorkerModule', () => {
|
|||
expect(swRegisterSpy).toHaveBeenCalledWith('sw.js', {scope: undefined});
|
||||
});
|
||||
|
||||
it('defaults to enabling the SW', async() => {
|
||||
it('defaults to enabling the SW', async () => {
|
||||
configTestBed({}, {enabled: false});
|
||||
await untilStable();
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -6,7 +6,7 @@
|
|||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ChangeDetectorRef, Component, EventEmitter, Input, NO_ERRORS_SCHEMA, NgModule, NgModuleFactory, NgZone, OnChanges, OnDestroy, Output, SimpleChange, SimpleChanges, Testability, destroyPlatform, forwardRef} from '@angular/core';
|
||||
import {ChangeDetectorRef, Component, destroyPlatform, EventEmitter, forwardRef, Input, NgModule, NgModuleFactory, NgZone, NO_ERRORS_SCHEMA, OnChanges, OnDestroy, Output, SimpleChange, SimpleChanges, Testability} from '@angular/core';
|
||||
import {async, fakeAsync, flushMicrotasks, tick} from '@angular/core/testing';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
|
||||
|
@ -23,7 +23,6 @@ declare global {
|
|||
|
||||
withEachNg1Version(() => {
|
||||
describe('adapter: ng1 to ng2', () => {
|
||||
|
||||
beforeEach(() => destroyPlatform());
|
||||
afterEach(() => destroyPlatform());
|
||||
|
||||
|
@ -232,7 +231,9 @@ withEachNg1Version(() => {
|
|||
})
|
||||
class Ng2 {
|
||||
l: any;
|
||||
constructor() { this.l = l; }
|
||||
constructor() {
|
||||
this.l = l;
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
|
@ -262,7 +263,9 @@ withEachNg1Version(() => {
|
|||
@Component({selector: 'my-app', template: '<my-child [value]="value"></my-child>'})
|
||||
class AppComponent {
|
||||
value?: number;
|
||||
constructor() { appComponent = this; }
|
||||
constructor() {
|
||||
appComponent = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
|
@ -272,7 +275,9 @@ withEachNg1Version(() => {
|
|||
class ChildComponent {
|
||||
valueFromPromise?: number;
|
||||
@Input()
|
||||
set value(v: number) { expect(NgZone.isInAngularZone()).toBe(true); }
|
||||
set value(v: number) {
|
||||
expect(NgZone.isInAngularZone()).toBe(true);
|
||||
}
|
||||
|
||||
constructor(private zone: NgZone) {}
|
||||
|
||||
|
@ -352,14 +357,15 @@ withEachNg1Version(() => {
|
|||
|
||||
const element = html('<ng2></ng2>');
|
||||
adapter.bootstrap(element, ['ng1']).ready((ref) => {
|
||||
expect(multiTrim(document.body.textContent !)).toBe('It works');
|
||||
expect(multiTrim(document.body.textContent!)).toBe('It works');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should bind properties, events', async(() => {
|
||||
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
||||
const ng1Module =
|
||||
angular.module_('ng1', []).value($EXCEPTION_HANDLER, (err: any) => { throw err; });
|
||||
const ng1Module = angular.module_('ng1', []).value($EXCEPTION_HANDLER, (err: any) => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
ng1Module.run(($rootScope: any) => {
|
||||
$rootScope.name = 'world';
|
||||
|
@ -409,8 +415,8 @@ withEachNg1Version(() => {
|
|||
}
|
||||
const actValue = changes[prop].currentValue;
|
||||
if (actValue != value) {
|
||||
throw new Error(
|
||||
`Expected changes record for'${prop}' to be '${value}' but was '${actValue}'`);
|
||||
throw new Error(`Expected changes record for'${prop}' to be '${
|
||||
value}' but was '${actValue}'`);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -458,7 +464,7 @@ withEachNg1Version(() => {
|
|||
| modelA: {{modelA}}; modelB: {{modelB}}; eventA: {{eventA}}; eventB: {{eventB}};
|
||||
</div>`);
|
||||
adapter.bootstrap(element, ['ng1']).ready((ref) => {
|
||||
expect(multiTrim(document.body.textContent !))
|
||||
expect(multiTrim(document.body.textContent!))
|
||||
.toEqual(
|
||||
'ignore: -; ' +
|
||||
'literal: Text; interpolate: Hello world; ' +
|
||||
|
@ -466,7 +472,7 @@ withEachNg1Version(() => {
|
|||
'modelA: newA; modelB: newB; eventA: aFired; eventB: bFired;');
|
||||
|
||||
ref.ng1RootScope.$apply('name = "everyone"');
|
||||
expect(multiTrim(document.body.textContent !))
|
||||
expect(multiTrim(document.body.textContent!))
|
||||
.toEqual(
|
||||
'ignore: -; ' +
|
||||
'literal: Text; interpolate: Hello everyone; ' +
|
||||
|
@ -475,7 +481,6 @@ withEachNg1Version(() => {
|
|||
|
||||
ref.dispose();
|
||||
});
|
||||
|
||||
}));
|
||||
|
||||
it('should support two-way binding and event listener', async(() => {
|
||||
|
@ -541,9 +546,9 @@ withEachNg1Version(() => {
|
|||
ngOnChangesCount = 0;
|
||||
firstChangesCount = 0;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
initialValue !: string;
|
||||
initialValue!: string;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() foo !: string;
|
||||
@Input() foo!: string;
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
this.ngOnChangesCount++;
|
||||
|
@ -590,7 +595,9 @@ withEachNg1Version(() => {
|
|||
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
||||
const ng1Module = angular.module_('ng1', []);
|
||||
|
||||
ng1Module.run(($rootScope: any /** TODO #9100 */) => { $rootScope.modelA = 'A'; });
|
||||
ng1Module.run(($rootScope: any /** TODO #9100 */) => {
|
||||
$rootScope.modelA = 'A';
|
||||
});
|
||||
|
||||
let ng2Instance: Ng2;
|
||||
@Component({selector: 'ng2', template: '{{_value}}'})
|
||||
|
@ -598,11 +605,21 @@ withEachNg1Version(() => {
|
|||
private _value: any = '';
|
||||
private _onChangeCallback: (_: any) => void = () => {};
|
||||
private _onTouchedCallback: () => void = () => {};
|
||||
constructor() { ng2Instance = this; }
|
||||
writeValue(value: any) { this._value = value; }
|
||||
registerOnChange(fn: any) { this._onChangeCallback = fn; }
|
||||
registerOnTouched(fn: any) { this._onTouchedCallback = fn; }
|
||||
doTouch() { this._onTouchedCallback(); }
|
||||
constructor() {
|
||||
ng2Instance = this;
|
||||
}
|
||||
writeValue(value: any) {
|
||||
this._value = value;
|
||||
}
|
||||
registerOnChange(fn: any) {
|
||||
this._onChangeCallback = fn;
|
||||
}
|
||||
registerOnTouched(fn: any) {
|
||||
this._onTouchedCallback = fn;
|
||||
}
|
||||
doTouch() {
|
||||
this._onTouchedCallback();
|
||||
}
|
||||
doChange(newValue: string) {
|
||||
this._value = newValue;
|
||||
this._onChangeCallback(newValue);
|
||||
|
@ -653,14 +670,18 @@ withEachNg1Version(() => {
|
|||
return {
|
||||
template: '<div ng-if="!destroyIt"><ng2></ng2></div>',
|
||||
controller: function($rootScope: any, $timeout: Function) {
|
||||
$timeout(() => { $rootScope.destroyIt = true; });
|
||||
$timeout(() => {
|
||||
$rootScope.destroyIt = true;
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@Component({selector: 'ng2', template: 'test'})
|
||||
class Ng2 {
|
||||
ngOnDestroy() { onDestroyed.emit('destroyed'); }
|
||||
ngOnDestroy() {
|
||||
onDestroyed.emit('destroyed');
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
|
@ -673,7 +694,9 @@ withEachNg1Version(() => {
|
|||
ng1Module.directive('ng2', adapter.downgradeNg2Component(Ng2));
|
||||
const element = html('<ng1></ng1>');
|
||||
adapter.bootstrap(element, ['ng1']).ready((ref) => {
|
||||
onDestroyed.subscribe(() => { ref.dispose(); });
|
||||
onDestroyed.subscribe(() => {
|
||||
ref.dispose();
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
||||
|
@ -689,7 +712,9 @@ withEachNg1Version(() => {
|
|||
|
||||
@Component({selector: 'ng2-inner', template: 'test'})
|
||||
class Ng2InnerComponent implements OnDestroy {
|
||||
ngOnDestroy() { destroyed = true; }
|
||||
ngOnDestroy() {
|
||||
destroyed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
|
@ -789,7 +814,7 @@ withEachNg1Version(() => {
|
|||
@Component({selector: 'ng2', template: 'ng2-{{ itemId }}(<ng-content></ng-content>)'})
|
||||
class Ng2Component {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
@Input() itemId !: string;
|
||||
@Input() itemId!: string;
|
||||
}
|
||||
|
||||
@NgModule({imports: [BrowserModule], declarations: [Ng2Component]})
|
||||
|
@ -838,7 +863,7 @@ withEachNg1Version(() => {
|
|||
ng1Module.directive('rootComponent', adapter.downgradeNg2Component(RootComponent));
|
||||
|
||||
document.body.innerHTML = '<root-component></root-component>';
|
||||
adapter.bootstrap(document.body.firstElementChild !, ['myExample']).ready((ref) => {
|
||||
adapter.bootstrap(document.body.firstElementChild!, ['myExample']).ready((ref) => {
|
||||
expect(multiTrim(document.body.textContent)).toEqual('It works!');
|
||||
ref.dispose();
|
||||
});
|
||||
|
@ -868,7 +893,9 @@ withEachNg1Version(() => {
|
|||
dataA = 'foo';
|
||||
dataB = 'bar';
|
||||
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
|
@ -888,8 +915,8 @@ withEachNg1Version(() => {
|
|||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
adapter.bootstrap(element, ['ng1Module']).ready(ref => {
|
||||
const ng1 = element.querySelector('ng1') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('ng1')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent)).toBe('Inside: foo, bar | Outside: foo, bar');
|
||||
|
||||
|
@ -932,7 +959,9 @@ withEachNg1Version(() => {
|
|||
dataA = {value: 'foo'};
|
||||
dataB = {value: 'bar'};
|
||||
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
|
@ -952,8 +981,8 @@ withEachNg1Version(() => {
|
|||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
adapter.bootstrap(element, ['ng1Module']).ready(ref => {
|
||||
const ng1 = element.querySelector('ng1') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('ng1')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent)).toBe('Inside: foo, bar | Outside: foo, bar');
|
||||
|
||||
|
@ -996,7 +1025,9 @@ withEachNg1Version(() => {
|
|||
dataA = {value: 'foo'};
|
||||
dataB = {value: 'bar'};
|
||||
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
|
@ -1016,8 +1047,8 @@ withEachNg1Version(() => {
|
|||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
adapter.bootstrap(element, ['ng1Module']).ready(ref => {
|
||||
const ng1 = element.querySelector('ng1') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('ng1')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent)).toBe('Inside: foo, bar | Outside: foo, bar');
|
||||
|
||||
|
@ -1077,8 +1108,8 @@ withEachNg1Version(() => {
|
|||
const element = html(`<ng2></ng2>`);
|
||||
|
||||
adapter.bootstrap(element, ['ng1Module']).ready(ref => {
|
||||
const ng1 = element.querySelector('ng1') !;
|
||||
const ng1Controller = angular.element(ng1).controller !('ng1');
|
||||
const ng1 = element.querySelector('ng1')!;
|
||||
const ng1Controller = angular.element(ng1).controller!('ng1');
|
||||
|
||||
expect(multiTrim(element.textContent)).toBe('Inside: - | Outside: foo, bar');
|
||||
|
||||
|
@ -1204,7 +1235,9 @@ withEachNg1Version(() => {
|
|||
restrict: 'E',
|
||||
template: '{{someText}} - Length: {{data.length}}',
|
||||
scope: {data: '='},
|
||||
controller: function($scope: any) { $scope.someText = 'ng1 - Data: ' + $scope.data; }
|
||||
controller: function($scope: any) {
|
||||
$scope.someText = 'ng1 - Data: ' + $scope.data;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -1248,7 +1281,9 @@ withEachNg1Version(() => {
|
|||
restrict: 'E',
|
||||
template: '{{someText}} - Length: {{data.length}}',
|
||||
scope: {data: '='},
|
||||
link: function($scope: any) { $scope.someText = 'ng1 - Data: ' + $scope.data; }
|
||||
link: function($scope: any) {
|
||||
$scope.someText = 'ng1 - Data: ' + $scope.data;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -1291,7 +1326,9 @@ withEachNg1Version(() => {
|
|||
cbFn(200, `${method}:${url}`);
|
||||
});
|
||||
|
||||
const ng1 = () => { return {templateUrl: 'url.html'}; };
|
||||
const ng1 = () => {
|
||||
return {templateUrl: 'url.html'};
|
||||
};
|
||||
ng1Module.directive('ng1', ng1);
|
||||
@Component({selector: 'ng2', template: '<ng1></ng1>'})
|
||||
class Ng2 {
|
||||
|
@ -1320,7 +1357,13 @@ withEachNg1Version(() => {
|
|||
cbFn(200, `${method}:${url}`);
|
||||
});
|
||||
|
||||
const ng1 = () => { return {templateUrl() { return 'url.html'; }}; };
|
||||
const ng1 = () => {
|
||||
return {
|
||||
templateUrl() {
|
||||
return 'url.html';
|
||||
}
|
||||
};
|
||||
};
|
||||
ng1Module.directive('ng1', ng1);
|
||||
@Component({selector: 'ng2', template: '<ng1></ng1>'})
|
||||
class Ng2 {
|
||||
|
@ -1345,7 +1388,9 @@ withEachNg1Version(() => {
|
|||
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
||||
const ng1Module = angular.module_('ng1', []);
|
||||
|
||||
const ng1 = () => { return {template: ''}; };
|
||||
const ng1 = () => {
|
||||
return {template: ''};
|
||||
};
|
||||
ng1Module.directive('ng1', ng1);
|
||||
|
||||
@Component({selector: 'ng2', template: '<ng1></ng1>'})
|
||||
|
@ -1371,7 +1416,13 @@ withEachNg1Version(() => {
|
|||
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
||||
const ng1Module = angular.module_('ng1', []);
|
||||
|
||||
const ng1 = () => { return {template() { return ''; }}; };
|
||||
const ng1 = () => {
|
||||
return {
|
||||
template() {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
};
|
||||
ng1Module.directive('ng1', ng1);
|
||||
|
||||
@Component({selector: 'ng2', template: '<ng1></ng1>'})
|
||||
|
@ -1398,7 +1449,9 @@ withEachNg1Version(() => {
|
|||
const ng1Module = angular.module_('ng1', []);
|
||||
ng1Module.run(($templateCache: any) => $templateCache.put('url.html', 'WORKS'));
|
||||
|
||||
const ng1 = () => { return {templateUrl: 'url.html'}; };
|
||||
const ng1 = () => {
|
||||
return {templateUrl: 'url.html'};
|
||||
};
|
||||
ng1Module.directive('ng1', ng1);
|
||||
|
||||
@Component({selector: 'ng2', template: '<ng1></ng1>'})
|
||||
|
@ -1431,13 +1484,20 @@ withEachNg1Version(() => {
|
|||
'{{ctl.scope}}; {{ctl.isClass}}; {{ctl.hasElement}}; {{ctl.isPublished()}}',
|
||||
controllerAs: 'ctl',
|
||||
controller: class {
|
||||
scope: any; hasElement: string; $element: any; isClass: any;
|
||||
scope: any;
|
||||
hasElement: string;
|
||||
$element: any;
|
||||
isClass: any;
|
||||
constructor($scope: any, $element: any) {
|
||||
this.verifyIAmAClass();
|
||||
this.scope = $scope.$parent.$parent == $scope.$root ? 'scope' : 'wrong-scope';
|
||||
this.hasElement = $element[0].nodeName;
|
||||
this.$element = $element;
|
||||
} verifyIAmAClass() { this.isClass = 'isClass'; } isPublished() {
|
||||
}
|
||||
verifyIAmAClass() {
|
||||
this.isClass = 'isClass';
|
||||
}
|
||||
isPublished() {
|
||||
return this.$element.controller('ng1') == this ? 'published' : 'not-published';
|
||||
}
|
||||
}
|
||||
|
@ -1543,7 +1603,9 @@ withEachNg1Version(() => {
|
|||
template: '{{ctl.status}}',
|
||||
require: 'ng1',
|
||||
controllerAs: 'ctrl',
|
||||
controller: class {status = 'WORKS';},
|
||||
controller: class {
|
||||
status = 'WORKS';
|
||||
},
|
||||
link: function(scope: any, element: any, attrs: any, linkController: any) {
|
||||
expect(scope.$root).toEqual($rootScope);
|
||||
expect(element[0].nodeName).toEqual('NG1');
|
||||
|
@ -1577,7 +1639,13 @@ withEachNg1Version(() => {
|
|||
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));
|
||||
const ng1Module = angular.module_('ng1', []);
|
||||
|
||||
const parent = () => { return {controller: class {parent = 'PARENT';}}; };
|
||||
const parent = () => {
|
||||
return {
|
||||
controller: class {
|
||||
parent = 'PARENT';
|
||||
}
|
||||
};
|
||||
};
|
||||
const ng1 = () => {
|
||||
return {
|
||||
scope: {title: '@'},
|
||||
|
@ -1585,7 +1653,9 @@ withEachNg1Version(() => {
|
|||
template: '{{parent.parent}}:{{ng1.status}}',
|
||||
require: ['ng1', '^parent', '?^^notFound'],
|
||||
controllerAs: 'ctrl',
|
||||
controller: class {status = 'WORKS';},
|
||||
controller: class {
|
||||
status = 'WORKS';
|
||||
},
|
||||
link: function(scope: any, element: any, attrs: any, linkControllers: any) {
|
||||
expect(linkControllers[0].status).toEqual('WORKS');
|
||||
expect(linkControllers[1].parent).toEqual('PARENT');
|
||||
|
@ -1633,16 +1703,21 @@ withEachNg1Version(() => {
|
|||
scope: {},
|
||||
bindToController: true,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {$onInit() { $onInitSpyA(); }}
|
||||
controller: class {
|
||||
$onInit() {
|
||||
$onInitSpyA();
|
||||
}
|
||||
}
|
||||
}))
|
||||
.directive('ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) {
|
||||
this.$onInit = $onInitSpyB;
|
||||
}
|
||||
}))
|
||||
.directive(
|
||||
'ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) { this.$onInit = $onInitSpyB; }
|
||||
}))
|
||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||
|
||||
@NgModule({
|
||||
|
@ -1718,7 +1793,9 @@ withEachNg1Version(() => {
|
|||
|
||||
@Component({selector: 'ng2', template: '<ng1-a></ng1-a> | <ng1-b></ng1-b>'})
|
||||
class Ng2Component {
|
||||
constructor(cd: ChangeDetectorRef) { changeDetector = cd; }
|
||||
constructor(cd: ChangeDetectorRef) {
|
||||
changeDetector = cd;
|
||||
}
|
||||
}
|
||||
|
||||
angular.module_('ng1', [])
|
||||
|
@ -1727,16 +1804,21 @@ withEachNg1Version(() => {
|
|||
scope: {},
|
||||
bindToController: true,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {$doCheck() { $doCheckSpyA(); }}
|
||||
controller: class {
|
||||
$doCheck() {
|
||||
$doCheckSpyA();
|
||||
}
|
||||
}
|
||||
}))
|
||||
.directive('ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) {
|
||||
this.$doCheck = $doCheckSpyB;
|
||||
}
|
||||
}))
|
||||
.directive(
|
||||
'ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) { this.$doCheck = $doCheckSpyB; }
|
||||
}))
|
||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||
|
||||
@NgModule({
|
||||
|
@ -1773,7 +1855,9 @@ withEachNg1Version(() => {
|
|||
|
||||
@Component({selector: 'ng2', template: '<ng1-a></ng1-a> | <ng1-b></ng1-b>'})
|
||||
class Ng2Component {
|
||||
constructor(cd: ChangeDetectorRef) { changeDetector = cd; }
|
||||
constructor(cd: ChangeDetectorRef) {
|
||||
changeDetector = cd;
|
||||
}
|
||||
}
|
||||
|
||||
angular.module_('ng1', [])
|
||||
|
@ -1835,16 +1919,21 @@ withEachNg1Version(() => {
|
|||
scope: {},
|
||||
bindToController: true,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {$postLink() { $postLinkSpyA(); }}
|
||||
controller: class {
|
||||
$postLink() {
|
||||
$postLinkSpyA();
|
||||
}
|
||||
}
|
||||
}))
|
||||
.directive('ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) {
|
||||
this.$postLink = $postLinkSpyB;
|
||||
}
|
||||
}))
|
||||
.directive(
|
||||
'ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) { this.$postLink = $postLinkSpyB; }
|
||||
}))
|
||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||
|
||||
@NgModule({
|
||||
|
@ -1924,7 +2013,9 @@ withEachNg1Version(() => {
|
|||
template: '<ng1-a [valA]="val"></ng1-a> | <ng1-b [valB]="val"></ng1-b>'
|
||||
})
|
||||
class Ng2Component {
|
||||
constructor() { ng2Instance = this; }
|
||||
constructor() {
|
||||
ng2Instance = this;
|
||||
}
|
||||
}
|
||||
|
||||
angular.module_('ng1', [])
|
||||
|
@ -1937,17 +2028,17 @@ withEachNg1Version(() => {
|
|||
this.$onChanges = $onChangesControllerSpyA;
|
||||
}
|
||||
}))
|
||||
.directive(
|
||||
'ng1B',
|
||||
() => ({
|
||||
template: '',
|
||||
scope: {valB: '<'},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {
|
||||
$onChanges(changes: SimpleChanges) { $onChangesControllerSpyB(changes); }
|
||||
}
|
||||
}))
|
||||
.directive('ng1B', () => ({
|
||||
template: '',
|
||||
scope: {valB: '<'},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {
|
||||
$onChanges(changes: SimpleChanges) {
|
||||
$onChangesControllerSpyB(changes);
|
||||
}
|
||||
}
|
||||
}))
|
||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component))
|
||||
.run(($rootScope: angular.IRootScopeService) => {
|
||||
Object.getPrototypeOf($rootScope).$onChanges = $onChangesScopeSpy;
|
||||
|
@ -2022,7 +2113,9 @@ withEachNg1Version(() => {
|
|||
})
|
||||
class Ng2Component {
|
||||
ng2Destroy: boolean = false;
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// On browsers that don't support `requestAnimationFrame` (IE 9, Android <= 4.3),
|
||||
|
@ -2036,16 +2129,21 @@ withEachNg1Version(() => {
|
|||
scope: {},
|
||||
bindToController: true,
|
||||
controllerAs: '$ctrl',
|
||||
controller: class {$onDestroy() { $onDestroySpyA(); }}
|
||||
controller: class {
|
||||
$onDestroy() {
|
||||
$onDestroySpyA();
|
||||
}
|
||||
}
|
||||
}))
|
||||
.directive('ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) {
|
||||
this.$onDestroy = $onDestroySpyB;
|
||||
}
|
||||
}))
|
||||
.directive(
|
||||
'ng1B', () => ({
|
||||
template: '',
|
||||
scope: {},
|
||||
bindToController: false,
|
||||
controllerAs: '$ctrl',
|
||||
controller: function(this: any) { this.$onDestroy = $onDestroySpyB; }
|
||||
}))
|
||||
.directive('ng2', adapter.downgradeNg2Component(Ng2Component));
|
||||
|
||||
@NgModule({
|
||||
|
@ -2112,7 +2210,9 @@ withEachNg1Version(() => {
|
|||
})
|
||||
class Ng2Component {
|
||||
ng2Destroy: boolean = false;
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// On browsers that don't support `requestAnimationFrame` (IE 9, Android <= 4.3),
|
||||
|
@ -2187,7 +2287,9 @@ withEachNg1Version(() => {
|
|||
@Component({selector: 'ng2', template: '<div *ngIf="!ng2Destroy"><ng1></ng1></div>'})
|
||||
class Ng2Component {
|
||||
ng2Destroy: boolean = false;
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// On browsers that don't support `requestAnimationFrame` (IE 9, Android <= 4.3),
|
||||
|
@ -2233,7 +2335,9 @@ withEachNg1Version(() => {
|
|||
@Component({selector: 'ng2', template: '<div *ngIf="!ng2Destroy"><ng1></ng1></div>'})
|
||||
class Ng2Component {
|
||||
ng2Destroy: boolean = false;
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// On browsers that don't support `requestAnimationFrame` (IE 9, Android <= 4.3),
|
||||
|
@ -2245,8 +2349,8 @@ withEachNg1Version(() => {
|
|||
.component('ng1', {
|
||||
controller: class {
|
||||
constructor(private $element: angular.IAugmentedJQuery) {} $onInit() {
|
||||
this.$element.on !('$destroy', elementDestroyListener);
|
||||
this.$element.contents !().on !('$destroy', descendantDestroyListener);
|
||||
this.$element.on!('$destroy', elementDestroyListener);
|
||||
this.$element.contents!().on!('$destroy', descendantDestroyListener);
|
||||
}
|
||||
},
|
||||
template: '<div></div>'
|
||||
|
@ -2287,8 +2391,8 @@ withEachNg1Version(() => {
|
|||
const ng1Component: angular.IComponent = {
|
||||
controller: class {
|
||||
constructor(private $element: angular.IAugmentedJQuery) {} $onInit() {
|
||||
this.$element.data !('test', 1);
|
||||
this.$element.contents !().data !('test', 2);
|
||||
this.$element.data!('test', 1);
|
||||
this.$element.contents!().data!('test', 2);
|
||||
|
||||
ng1ComponentElement = this.$element;
|
||||
}
|
||||
|
@ -2301,7 +2405,9 @@ withEachNg1Version(() => {
|
|||
class Ng2ComponentA {
|
||||
destroyIt = false;
|
||||
|
||||
constructor() { ng2ComponentAInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentAInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'ng2B', template: '<ng1></ng1>'})
|
||||
|
@ -2330,15 +2436,15 @@ withEachNg1Version(() => {
|
|||
const $rootScope = ref.ng1RootScope as any;
|
||||
tick();
|
||||
$rootScope.$digest();
|
||||
expect(ng1ComponentElement.data !('test')).toBe(1);
|
||||
expect(ng1ComponentElement.contents !().data !('test')).toBe(2);
|
||||
expect(ng1ComponentElement.data!('test')).toBe(1);
|
||||
expect(ng1ComponentElement.contents!().data!('test')).toBe(2);
|
||||
|
||||
ng2ComponentAInstance.destroyIt = true;
|
||||
tick();
|
||||
$rootScope.$digest();
|
||||
|
||||
expect(ng1ComponentElement.data !('test')).toBeUndefined();
|
||||
expect(ng1ComponentElement.contents !().data !('test')).toBeUndefined();
|
||||
expect(ng1ComponentElement.data!('test')).toBeUndefined();
|
||||
expect(ng1ComponentElement.contents!().data!('test')).toBeUndefined();
|
||||
});
|
||||
}));
|
||||
|
||||
|
@ -2353,10 +2459,10 @@ withEachNg1Version(() => {
|
|||
const ng1Component: angular.IComponent = {
|
||||
controller: class {
|
||||
constructor(private $element: angular.IAugmentedJQuery) {} $onInit() {
|
||||
ng1DescendantElement = this.$element.contents !();
|
||||
ng1DescendantElement = this.$element.contents!();
|
||||
|
||||
this.$element.on !('click', elementClickListener);
|
||||
ng1DescendantElement.on !('click', descendantClickListener);
|
||||
this.$element.on!('click', elementClickListener);
|
||||
ng1DescendantElement.on!('click', descendantClickListener);
|
||||
}
|
||||
},
|
||||
template: '<div></div>'
|
||||
|
@ -2367,7 +2473,9 @@ withEachNg1Version(() => {
|
|||
class Ng2ComponentA {
|
||||
destroyIt = false;
|
||||
|
||||
constructor() { ng2ComponentAInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentAInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'ng2B', template: '<ng1></ng1>'})
|
||||
|
@ -2420,7 +2528,11 @@ withEachNg1Version(() => {
|
|||
const ng1Directive: angular.IDirective = {
|
||||
template: '',
|
||||
link: {pre: () => log.push('ng1-pre')},
|
||||
controller: class {constructor() { log.push('ng1-ctrl'); }}
|
||||
controller: class {
|
||||
constructor() {
|
||||
log.push('ng1-ctrl');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng2Component`
|
||||
|
@ -2577,7 +2689,11 @@ withEachNg1Version(() => {
|
|||
const ng1Directive: angular.IDirective = {
|
||||
template: '',
|
||||
link: () => log.push('ng1-post'),
|
||||
controller: class {$postLink() { log.push('ng1-$post'); }}
|
||||
controller: class {
|
||||
$postLink() {
|
||||
log.push('ng1-$post');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng2Component`
|
||||
|
@ -2627,13 +2743,17 @@ withEachNg1Version(() => {
|
|||
class Ng2ComponentA {
|
||||
value = 'foo';
|
||||
showB = false;
|
||||
constructor() { ng2ComponentAInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentAInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
@Component({selector: 'ng2B', template: 'ng2B({{ value }})'})
|
||||
class Ng2ComponentB {
|
||||
value = 'bar';
|
||||
constructor() { ng2ComponentBInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentBInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
|
@ -2678,7 +2798,10 @@ withEachNg1Version(() => {
|
|||
template: 'ng1(<div ng-transclude>{{ $ctrl.value }}</div>)',
|
||||
transclude: true,
|
||||
controller: class {
|
||||
value = 'from-ng1'; constructor() { ng1ControllerInstances.push(this); }
|
||||
value = 'from-ng1';
|
||||
constructor() {
|
||||
ng1ControllerInstances.push(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2697,7 +2820,9 @@ withEachNg1Version(() => {
|
|||
})
|
||||
class Ng2Component {
|
||||
value = 'from-ng2';
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
|
@ -2756,7 +2881,9 @@ withEachNg1Version(() => {
|
|||
class Ng2Component {
|
||||
x = 'foo';
|
||||
y = 'bar';
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
|
@ -2798,8 +2925,12 @@ withEachNg1Version(() => {
|
|||
const ng1Component: angular.IComponent = {
|
||||
template: 'ng1(default(<div ng-transclude="">fallback-{{ $ctrl.value }}</div>))',
|
||||
transclude: {slotX: 'contentX', slotY: 'contentY'},
|
||||
controller:
|
||||
class {value = 'ng1'; constructor() { ng1ControllerInstances.push(this); }}
|
||||
controller: class {
|
||||
value = 'ng1';
|
||||
constructor() {
|
||||
ng1ControllerInstances.push(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Define `Ng2Component`
|
||||
|
@ -2830,7 +2961,9 @@ withEachNg1Version(() => {
|
|||
class Ng2Component {
|
||||
x = 'foo';
|
||||
y = 'bar';
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
|
@ -2880,7 +3013,11 @@ withEachNg1Version(() => {
|
|||
)`,
|
||||
transclude: {slotX: '?contentX', slotY: '?contentY'},
|
||||
controller: class {
|
||||
x = 'ng1X'; y = 'ng1Y'; constructor() { ng1ControllerInstances.push(this); }
|
||||
x = 'ng1X';
|
||||
y = 'ng1Y';
|
||||
constructor() {
|
||||
ng1ControllerInstances.push(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -2896,7 +3033,9 @@ withEachNg1Version(() => {
|
|||
class Ng2Component {
|
||||
x = 'ng2X';
|
||||
y = 'ng2Y';
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
|
@ -3000,7 +3139,9 @@ withEachNg1Version(() => {
|
|||
x = 'foo';
|
||||
y = 'bar';
|
||||
show = true;
|
||||
constructor() { ng2ComponentInstance = this; }
|
||||
constructor() {
|
||||
ng2ComponentInstance = this;
|
||||
}
|
||||
}
|
||||
|
||||
// Define `ng1Module`
|
||||
|
@ -3202,13 +3343,18 @@ withEachNg1Version(() => {
|
|||
const ng1Module = angular.module_('ng1', []);
|
||||
let a1Injector: angular.IInjectorService|undefined;
|
||||
ng1Module.run([
|
||||
'$injector', function($injector: angular.IInjectorService) { a1Injector = $injector; }
|
||||
'$injector',
|
||||
function($injector: angular.IInjectorService) {
|
||||
a1Injector = $injector;
|
||||
}
|
||||
]);
|
||||
|
||||
const element = html('<div></div>');
|
||||
window.name = 'NG_DEFER_BOOTSTRAP!' + window.name;
|
||||
|
||||
adapter.bootstrap(element, [ng1Module.name]).ready((ref) => { ref.dispose(); });
|
||||
adapter.bootstrap(element, [ng1Module.name]).ready((ref) => {
|
||||
ref.dispose();
|
||||
});
|
||||
|
||||
tick(100);
|
||||
|
||||
|
@ -3275,7 +3421,7 @@ withEachNg1Version(() => {
|
|||
|
||||
document.body.innerHTML = '<ng2 name="World">project</ng2>';
|
||||
|
||||
adapter.bootstrap(document.body.firstElementChild !, ['myExample']).ready((ref) => {
|
||||
adapter.bootstrap(document.body.firstElementChild!, ['myExample']).ready((ref) => {
|
||||
expect(multiTrim(document.body.textContent))
|
||||
.toEqual('ng2[ng1[Hello World!](transclude)](project)');
|
||||
ref.dispose();
|
||||
|
|
|
@ -284,11 +284,7 @@ describe('bluebird promise', () => {
|
|||
.each(
|
||||
BluebirdPromise.map(arr, (item: number) => BluebirdPromise.resolve(item)),
|
||||
(r: number, idx: number) => {
|
||||
<<<<<<< HEAD
|
||||
expect(r).toBe(arr[idx]);
|
||||
=======
|
||||
expect(r === arr[idx]).toBeTrue();
|
||||
>>>>>>> 253023848d... build: update jasmine to 3.5
|
||||
expect(Zone.current.name).toEqual('bluebird');
|
||||
})
|
||||
.then((r: any) => {
|
||||
|
@ -309,11 +305,7 @@ describe('bluebird promise', () => {
|
|||
.mapSeries(
|
||||
BluebirdPromise.map(arr, (item: number) => BluebirdPromise.resolve(item)),
|
||||
(r: number, idx: number) => {
|
||||
<<<<<<< HEAD
|
||||
expect(r).toBe(arr[idx]);
|
||||
=======
|
||||
expect(r === arr[idx]).toBeTrue();
|
||||
>>>>>>> 253023848d... build: update jasmine to 3.5
|
||||
expect(Zone.current.name).toEqual('bluebird');
|
||||
})
|
||||
.then((r: any) => {
|
||||
|
|
|
@ -21,7 +21,9 @@ describe('crypto test', () => {
|
|||
const zoneASpec = {
|
||||
name: 'A',
|
||||
onScheduleTask: (delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task):
|
||||
Task => { return delegate.scheduleTask(targetZone, task); }
|
||||
Task => {
|
||||
return delegate.scheduleTask(targetZone, task);
|
||||
}
|
||||
};
|
||||
const zoneA = Zone.current.fork(zoneASpec);
|
||||
spyOn(zoneASpec, 'onScheduleTask').and.callThrough();
|
||||
|
@ -44,7 +46,9 @@ describe('crypto test', () => {
|
|||
const zoneASpec = {
|
||||
name: 'A',
|
||||
onScheduleTask: (delegate: ZoneDelegate, currentZone: Zone, targetZone: Zone, task: Task):
|
||||
Task => { return delegate.scheduleTask(targetZone, task); }
|
||||
Task => {
|
||||
return delegate.scheduleTask(targetZone, task);
|
||||
}
|
||||
};
|
||||
const zoneA = Zone.current.fork(zoneASpec);
|
||||
spyOn(zoneASpec, 'onScheduleTask').and.callThrough();
|
||||
|
|
Loading…
Reference in New Issue