New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(upgrade): assert correct interleaving of evaluation. #4436
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,44 +19,80 @@ export function main() { | |
it('should have angular 1 loaded', () => expect(angular.version.major).toBe(1)); | ||
|
||
it('should instantiate ng2 in ng1 template', inject([AsyncTestCompleter], (async) => { | ||
var Ng2 = Component({selector: 'ng2'}) | ||
.View({template: `{{ 'NG2' }}`}) | ||
.Class({constructor: function() {}}); | ||
|
||
var element = html("<div>{{ 'ng1-' }}<ng2>~~</ng2>{{ '-ng1' }}</div>"); | ||
|
||
var upgradeModule: UpgradeModule = createUpgradeModule(); | ||
upgradeModule.importNg2Component(SimpleComponent); | ||
upgradeModule.importNg2Component(Ng2); | ||
upgradeModule.bootstrap(element).ready(() => { | ||
expect(document.body.textContent).toEqual("ng1-NG2-ng1"); | ||
async.done(); | ||
}); | ||
})); | ||
|
||
it('should instantiate ng1 in ng2 template', inject([AsyncTestCompleter], (async) => { | ||
var upgradeModule: UpgradeModule = createUpgradeModule(); | ||
|
||
var Ng2 = Component({selector: 'ng2-1'}) | ||
.View({ | ||
template: `{{ 'ng2(' }}<ng1></ng1>{{ ')' }}`, | ||
directives: [upgradeModule.exportAsNg2Component('ng1')] | ||
}) | ||
.Class({constructor: function() {}}); | ||
|
||
upgradeModule.ng1Module.directive('ng1', | ||
() => { return {template: 'ng1 {{ "WORKS" }}!'}; }); | ||
upgradeModule.importNg2Component(Ng2); | ||
|
||
var element = html("<div>{{'ng1('}}<ng2-1></ng2-1>{{')'}}</div>"); | ||
|
||
ng1inNg2Module.bootstrap(element).ready(() => { | ||
upgradeModule.bootstrap(element).ready(() => { | ||
expect(document.body.textContent).toEqual("ng1(ng2(ng1 WORKS!))"); | ||
async.done(); | ||
}); | ||
})); | ||
}); | ||
} | ||
|
||
@Component({selector: 'ng2'}) | ||
@View({template: `{{ 'NG2' }}`}) | ||
class SimpleComponent { | ||
} | ||
describe('scope/component change-detection', () => { | ||
it('should interleve scope and component expressions', inject([AsyncTestCompleter], (async) { | ||
var log = []; | ||
var l = function(value) { | ||
log.push(value); | ||
return value + ';'; | ||
}; | ||
var upgrMod: UpgradeModule = createUpgradeModule(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other tests can this variable Not sure if you know, but even if you omit the type here (like this Essentially:
is the same as
|
||
|
||
var ng1inNg2Module: UpgradeModule = createUpgradeModule(); | ||
upgrMod.ng1Module.directive('ng1a', () => { return {template: "{{ l('ng1a') }}"}; }); | ||
upgrMod.ng1Module.directive('ng1b', () => { return {template: "{{ l('ng1b') }}"}; }); | ||
upgrMod.ng1Module.run(($rootScope) => { | ||
$rootScope.l = l; | ||
$rootScope.reset = () => log.length = 0; | ||
}); | ||
|
||
@Component({selector: 'ng2-1'}) | ||
@View({ | ||
template: `{{ 'ng2(' }}<ng1></ng1>{{ ')' }}`, | ||
directives: [ng1inNg2Module.exportAsNg2Component('ng1')] | ||
}) | ||
class Ng2ContainsNg1 { | ||
} | ||
upgrMod.importNg2Component( | ||
Component({selector: 'ng2'}) | ||
.View({ | ||
template: `{{l('2A')}}<ng1a></ng1a>{{l('2B')}}<ng1b></ng1b>{{l('2C')}}`, | ||
directives: [ | ||
upgrMod.exportAsNg2Component('ng1a'), | ||
upgrMod.exportAsNg2Component('ng1b') | ||
] | ||
}) | ||
.Class({constructor: function() { this.l = l; }})); | ||
|
||
ng1inNg2Module.ng1Module.directive('ng1', () => { return {template: 'ng1 {{ "WORKS" }}!'}; }); | ||
ng1inNg2Module.importNg2Component(Ng2ContainsNg1); | ||
var element = html("<div>{{reset(); l('1A');}}<ng2>{{l('1B')}}</ng2>{{l('1C')}}</div>"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using bindings with side effects is confusing. I think the test will look simpler if you just assert the log starts with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't do that duo to: angular/angular.js#12983 Which is why I need to reset so that I don't depend on incorrect behavior. |
||
upgrMod.bootstrap(element).ready(() => { | ||
expect(document.body.textContent).toEqual("1A;2A;ng1a;2B;ng1b;2C;1C;"); | ||
// https://github.com/angular/angular.js/issues/12983 | ||
expect(log).toEqual(['1A', '1B', '1C', '2A', '2B', '2C', 'ng1a', 'ng1b']); | ||
async.done(); | ||
}); | ||
})); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
function html(html: string): Element { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inject Log service instead. See test_lib/utils.ts