From 844e89f277f44d462aadd602a48d7b9f3fb92729 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 3 Dec 2017 09:33:56 -0500 Subject: [PATCH] correctly mount await block that has an anchor --- src/generators/dom/visitors/AwaitBlock.ts | 2 +- .../await-then-catch-multiple/_config.js | 53 +++++++++++++++++++ .../await-then-catch-multiple/main.html | 15 ++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/await-then-catch-multiple/_config.js create mode 100644 test/runtime/samples/await-then-catch-multiple/main.html diff --git a/src/generators/dom/visitors/AwaitBlock.ts b/src/generators/dom/visitors/AwaitBlock.ts index b4372831a8..c0d5c25b85 100644 --- a/src/generators/dom/visitors/AwaitBlock.ts +++ b/src/generators/dom/visitors/AwaitBlock.ts @@ -110,7 +110,7 @@ export default function visitAwaitBlock( const anchorNode = state.parentNode ? 'null' : 'anchor'; block.builders.mount.addBlock(deindent` - ${await_block}.m(${targetNode}, ${anchor}); + ${await_block}.m(${targetNode}, ${anchorNode}); `); const conditions = []; diff --git a/test/runtime/samples/await-then-catch-multiple/_config.js b/test/runtime/samples/await-then-catch-multiple/_config.js new file mode 100644 index 0000000000..2866fea883 --- /dev/null +++ b/test/runtime/samples/await-then-catch-multiple/_config.js @@ -0,0 +1,53 @@ +let fulfil; + +let thePromise = new Promise(f => { + fulfil = f; +}); + +export default { + data: { + thePromise + }, + + html: ` +

loading...

+

loading...

+ `, + + test(assert, component, target) { + fulfil(42); + + return thePromise + .then(() => { + assert.htmlEqual(target.innerHTML, ` +

the value is 42

+

the value is 42

+ `); + + let reject; + + thePromise = new Promise((f, r) => { + reject = r; + }); + + component.set({ + thePromise + }); + + assert.htmlEqual(target.innerHTML, ` +

loading...

+

loading...

+ `); + + reject(new Error('something broke')); + + return thePromise.catch(() => {}); + }) + .then(() => { + assert.htmlEqual(target.innerHTML, ` +

oh no! something broke

+

oh no! something broke

+ `); + }); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/await-then-catch-multiple/main.html b/test/runtime/samples/await-then-catch-multiple/main.html new file mode 100644 index 0000000000..eb071c27a8 --- /dev/null +++ b/test/runtime/samples/await-then-catch-multiple/main.html @@ -0,0 +1,15 @@ +{{#await thePromise}} +

loading...

+{{then theValue}} +

the value is {{theValue}}

+{{catch theError}} +

oh no! {{theError.message}}

+{{/await}} + +{{#await thePromise}} +

loading...

+{{then theValue}} +

the value is {{theValue}}

+{{catch theError}} +

oh no! {{theError.message}}

+{{/await}} \ No newline at end of file