Skip to content

Commit

Permalink
fix(animations): stringify state values before running the animation
Browse files Browse the repository at this point in the history
  • Loading branch information
matsko committed Nov 21, 2016
1 parent 491d5a2 commit 3f35068
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
6 changes: 4 additions & 2 deletions modules/@angular/compiler/src/compiler_util/render_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ export function triggerAnimation(
animationTransitionVar
.set(animationFnExpr.callFn([
view, renderElement,
lastRenderValue.equals(unitializedValue).conditional(emptyStateValue, lastRenderValue),
renderValue.equals(unitializedValue).conditional(emptyStateValue, renderValue)
lastRenderValue.equals(unitializedValue)
.conditional(emptyStateValue, lastRenderValue.callMethod('toString', [])),
renderValue.equals(unitializedValue)
.conditional(emptyStateValue, renderValue.callMethod('toString', []))
]))
.toDeclStmt());

Expand Down
44 changes: 44 additions & 0 deletions modules/@angular/core/test/animation/animation_integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,50 @@ function declareTests({useJit}: {useJit: boolean}) {
expect(keyframes2[1]).toEqual([1, {'opacity': '0'}]);
}));

it('should allow `true` and `false` to be recognized as `true` and `false` within animation states',
fakeAsync(() => {
TestBed.overrideComponent(DummyIfCmp, {
set: {
template: `
<div [@myAnimation]="exp" (@myAnimation.start)="callback($event)"></div>
`,
animations: [trigger('myAnimation', [transition('true <=> false', animate(543))])]
}
});

const driver = TestBed.get(AnimationDriver) as MockAnimationDriver;
const fixture = TestBed.createComponent(DummyIfCmp);
const cmp = fixture.componentInstance;
fixture.detectChanges();
flushMicrotasks();

let lastFromState: string;
let lastToState: string;
cmp.callback = function(event: AnimationTransitionEvent) {
lastFromState = event.fromState;
lastToState = event.toState;
};
driver.log = [];

cmp.exp = true;
fixture.detectChanges();
flushMicrotasks();

let time = driver.log.pop()['duration'];
expect(time).toEqual(543);
expect(lastFromState).toBe('false');
expect(lastToState).toBe('true');

cmp.exp = false;
fixture.detectChanges();
flushMicrotasks();

time = driver.log.pop()['duration'];
expect(time).toEqual(543);
expect(lastFromState).toBe('true');
expect(lastToState).toBe('false');
}));

it('should animate the element when the expression changes between states',
fakeAsync(
() => {
Expand Down

0 comments on commit 3f35068

Please sign in to comment.