Skip to content

Commit

Permalink
Ignore data-amp-bind-foo if [foo] already exists, add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
William Chou committed May 18, 2018
1 parent ae5cf40 commit ed5edf2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions extensions/amp-bind/0.1/bind-impl.js
Expand Up @@ -715,6 +715,10 @@ export class Bind {
property = attr.substr(1, attr.length - 2);
} else if (startsWith(attr, 'data-amp-bind-')) {
property = attr.substr(14);
// Ignore `data-amp-bind-foo` if `[foo]` already exists.
if (element.hasAttribute(`[${property}]`)) {
property = null;
}
}

if (property) {
Expand Down
21 changes: 21 additions & 0 deletions extensions/amp-bind/0.1/test/integration/test-bind-impl.js
Expand Up @@ -275,6 +275,27 @@ describe.configure().ifNewChrome().run('Bind', function() {
});
});

it('should support data-amp-bind-* syntax', () => {
const element = createElement(env, container, 'data-amp-bind-text="1+1"');
expect(bind.numberOfBindings()).to.equal(0);
expect(element.textContent).to.equal('');
return onBindReadyAndSetState(env, bind, {}).then(() => {
expect(bind.numberOfBindings()).to.equal(1);
expect(element.textContent).to.equal('2');
});
});

it('should prefer [foo] over data-amp-bind-foo', () => {
const element = createElement(
env, container, '[text]="1+1" data-amp-bind-text="2+2"');
expect(bind.numberOfBindings()).to.equal(0);
expect(element.textContent).to.equal('');
return onBindReadyAndSetState(env, bind, {}).then(() => {
expect(bind.numberOfBindings()).to.equal(1);
expect(element.textContent).to.equal('2');
});
});

it('should call createTreeWalker() with all params', () => {
const spy = env.sandbox.spy(env.win.document, 'createTreeWalker');
createElement(env, container, '[text]="1+1"');
Expand Down

0 comments on commit ed5edf2

Please sign in to comment.