fix more tests

pull/4297/head
Tan Li Hau 6 years ago
parent c8232107a6
commit 6fb365e735

@ -55,13 +55,9 @@ export default class AttributeWrapper {
const element = this.parent; const element = this.parent;
const name = fix_attribute_casing(this.node.name); const name = fix_attribute_casing(this.node.name);
const metadata = this.get_metadata();
const is_indirectly_bound_value = this.is_indirectly_bound_value(); const is_indirectly_bound_value = this.is_indirectly_bound_value();
const property_name = is_indirectly_bound_value const property_name = this.get_property_name();
? '__value'
: metadata && metadata.property_name;
// xlink is a special case... we could maybe extend this to generic // xlink is a special case... we could maybe extend this to generic
// namespaced attributes but I'm not sure that's applicable in // namespaced attributes but I'm not sure that's applicable in
@ -185,6 +181,14 @@ export default class AttributeWrapper {
} }
} }
get_property_name() {
const metadata = this.get_metadata();
const is_indirectly_bound_value = this.is_indirectly_bound_value();
return is_indirectly_bound_value
? '__value'
: metadata && metadata.property_name;
}
get_metadata() { get_metadata() {
if (this.parent.node.namespace) return null; if (this.parent.node.namespace) return null;
const metadata = attribute_lookup[fix_attribute_casing(this.node.name)]; const metadata = attribute_lookup[fix_attribute_casing(this.node.name)];

@ -405,7 +405,7 @@ export default class ElementWrapper extends Wrapper {
get_render_statement(block: Block) { get_render_statement(block: Block) {
const { name, namespace } = this.node; const { name, namespace } = this.node;
if (namespace === 'http://www.w3.org/2000/svg') { if (namespace === namespaces.svg) {
return x`@svg_element("${name}")`; return x`@svg_element("${name}")`;
} }
@ -422,9 +422,9 @@ export default class ElementWrapper extends Wrapper {
} }
get_claim_statement(nodes: Identifier) { get_claim_statement(nodes: Identifier) {
const attributes = this.node.attributes const attributes = this.attributes
.filter((attr) => attr.type === 'Attribute') .filter((attr) => attr.node.type === 'Attribute' && !attr.get_property_name())
.map((attr) => p`${fix_attribute_casing(attr.name)}: true`); .map((attr) => p`${fix_attribute_casing(attr.node.name)}: true`);
const name = this.node.namespace const name = this.node.namespace
? this.node.name ? this.node.name

@ -146,8 +146,6 @@ describe("runtime", () => {
throw err; throw err;
} }
if (config.before_test) config.before_test();
// Put things we need on window for testing // Put things we need on window for testing
window.SvelteComponent = SvelteComponent; window.SvelteComponent = SvelteComponent;
@ -160,10 +158,11 @@ describe("runtime", () => {
const SsrSvelteComponent = require(`./samples/${dir}/main.svelte`).default; const SsrSvelteComponent = require(`./samples/${dir}/main.svelte`).default;
const { html } = SsrSvelteComponent.render(config.props); const { html } = SsrSvelteComponent.render(config.props);
target.innerHTML = html; target.innerHTML = html;
delete compileOptions.generate; delete compileOptions.generate;
} }
if (config.before_test) config.before_test();
const warnings = []; const warnings = [];
const warn = console.warn; const warn = console.warn;
console.warn = warning => { console.warn = warning => {
@ -193,9 +192,7 @@ describe("runtime", () => {
throw new Error("Received unexpected warnings"); throw new Error("Received unexpected warnings");
} }
if (hydrate && config.ssrHtml) { if (config.html) {
assert.htmlEqual(target.innerHTML, config.ssrHtml);
} else if (config.html) {
assert.htmlEqual(target.innerHTML, config.html); assert.htmlEqual(target.innerHTML, config.html);
} }

@ -11,6 +11,9 @@ export default {
html: `<p>potato</p>`, html: `<p>potato</p>`,
before_test() {
count = 0;
},
test({ assert, component, target }) { test({ assert, component, target }) {
assert.equal(count, 1); assert.equal(count, 1);

@ -17,6 +17,11 @@ export default {
html: `<p>potato</p>`, html: `<p>potato</p>`,
before_test() {
count_a = 0;
count_b = 0;
},
test({ assert, component, target }) { test({ assert, component, target }) {
assert.equal(count_a, 1); assert.equal(count_a, 1);
assert.equal(count_b, 0); assert.equal(count_b, 0);

@ -2,7 +2,9 @@ import order from './order.js';
export default { export default {
skip_if_ssr: true, skip_if_ssr: true,
before_test() {
order.length = 0;
},
test({ assert, component, target, compileOptions }) { test({ assert, component, target, compileOptions }) {
if (compileOptions.hydratable) { if (compileOptions.hydratable) {
assert.deepEqual(order, [ assert.deepEqual(order, [
@ -44,6 +46,5 @@ export default {
]); ]);
} }
order.length = 0;
}, },
}; };

@ -3,6 +3,9 @@ import order from './order.js';
export default { export default {
skip_if_ssr: true, skip_if_ssr: true,
before_test() {
order.length = 0;
},
test({ assert }) { test({ assert }) {
assert.deepEqual(order, [ assert.deepEqual(order, [
'beforeUpdate', 'beforeUpdate',
@ -10,7 +13,5 @@ export default {
'onMount', 'onMount',
'afterUpdate' 'afterUpdate'
]); ]);
order.length = 0;
} }
}; };

@ -1,9 +1,14 @@
export default { export default {
skip_if_ssr: true,
html: ` html: `
<div>foo</div> <div>foo</div>
<div>foo<div>foo</div></div> <div>foo<div>foo</div></div>
`, `,
ssrHtml: `
<noscript>foo</noscript>
<div>foo<noscript>foo</noscript></div>
<div>foo<div>foo<noscript>foo</noscript></div></div>
`,
}; };

Loading…
Cancel
Save