mirror of https://github.com/sveltejs/svelte
parent
5f51856f86
commit
837d248257
@ -1,43 +1,48 @@
|
||||
export default {
|
||||
data: {
|
||||
count: 42
|
||||
count: 42,
|
||||
},
|
||||
|
||||
html: `
|
||||
<input type='number'>
|
||||
<input type=number>
|
||||
<p>number 42</p>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const input = target.querySelector( 'input' );
|
||||
assert.equal( input.value, '42' );
|
||||
ssrHtml: `
|
||||
<input type=number value=42>
|
||||
<p>number 42</p>
|
||||
`,
|
||||
|
||||
const event = new window.Event( 'input' );
|
||||
test(assert, component, target, window) {
|
||||
const input = target.querySelector('input');
|
||||
assert.equal(input.value, '42');
|
||||
|
||||
const event = new window.Event('input');
|
||||
|
||||
input.value = '43';
|
||||
input.dispatchEvent( event );
|
||||
input.dispatchEvent(event);
|
||||
|
||||
assert.equal( component.get().count, 43 );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
assert.equal(component.get().count, 43);
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input type='number'>
|
||||
<p>number 43</p>
|
||||
` );
|
||||
`);
|
||||
|
||||
component.set({ count: 44 });
|
||||
assert.equal( input.value, '44' );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
assert.equal(input.value, '44');
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input type='number'>
|
||||
<p>number 44</p>
|
||||
` );
|
||||
`);
|
||||
|
||||
// empty string should be treated as undefined
|
||||
input.value = '';
|
||||
input.dispatchEvent( event );
|
||||
input.dispatchEvent(event);
|
||||
|
||||
assert.equal( component.get().count, undefined );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
assert.equal(component.get().count, undefined);
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input type='number'>
|
||||
<p>undefined undefined</p>
|
||||
` );
|
||||
}
|
||||
`);
|
||||
},
|
||||
};
|
||||
|
@ -1,33 +1,38 @@
|
||||
export default {
|
||||
data: {
|
||||
count: 42
|
||||
count: 42,
|
||||
},
|
||||
|
||||
html: `
|
||||
<input type='range'>
|
||||
<input type=range>
|
||||
<p>number 42</p>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const input = target.querySelector( 'input' );
|
||||
assert.equal( input.value, '42' );
|
||||
ssrHtml: `
|
||||
<input type=range value=42>
|
||||
<p>number 42</p>
|
||||
`,
|
||||
|
||||
const event = new window.Event( 'change' );
|
||||
test(assert, component, target, window) {
|
||||
const input = target.querySelector('input');
|
||||
assert.equal(input.value, '42');
|
||||
|
||||
const event = new window.Event('change');
|
||||
|
||||
input.value = '43';
|
||||
input.dispatchEvent( event );
|
||||
input.dispatchEvent(event);
|
||||
|
||||
assert.equal( component.get().count, 43 );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
assert.equal(component.get().count, 43);
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input type='range'>
|
||||
<p>number 43</p>
|
||||
` );
|
||||
`);
|
||||
|
||||
component.set({ count: 44 });
|
||||
assert.equal( input.value, '44' );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
assert.equal(input.value, '44');
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input type='range'>
|
||||
<p>number 44</p>
|
||||
` );
|
||||
}
|
||||
`);
|
||||
},
|
||||
};
|
||||
|
@ -1,33 +1,38 @@
|
||||
export default {
|
||||
data: {
|
||||
count: 42
|
||||
count: 42,
|
||||
},
|
||||
|
||||
html: `
|
||||
<input type='range'>
|
||||
<input type=range>
|
||||
<p>number 42</p>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const input = target.querySelector( 'input' );
|
||||
assert.equal( input.value, '42' );
|
||||
ssrHtml: `
|
||||
<input type=range value=42>
|
||||
<p>number 42</p>
|
||||
`,
|
||||
|
||||
const event = new window.Event( 'input' );
|
||||
test(assert, component, target, window) {
|
||||
const input = target.querySelector('input');
|
||||
assert.equal(input.value, '42');
|
||||
|
||||
const event = new window.Event('input');
|
||||
|
||||
input.value = '43';
|
||||
input.dispatchEvent( event );
|
||||
input.dispatchEvent(event);
|
||||
|
||||
assert.equal( component.get().count, 43 );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
assert.equal(component.get().count, 43);
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input type='range'>
|
||||
<p>number 43</p>
|
||||
` );
|
||||
`);
|
||||
|
||||
component.set({ count: 44 });
|
||||
assert.equal( input.value, '44' );
|
||||
assert.htmlEqual( target.innerHTML, `
|
||||
assert.equal(input.value, '44');
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input type='range'>
|
||||
<p>number 44</p>
|
||||
` );
|
||||
}
|
||||
`);
|
||||
},
|
||||
};
|
||||
|
@ -1,29 +1,69 @@
|
||||
export default {
|
||||
data: {
|
||||
items: [
|
||||
'one',
|
||||
'two',
|
||||
'three'
|
||||
]
|
||||
items: ['one', 'two', 'three'],
|
||||
},
|
||||
html: `<div><input><p>one</p></div><div><input><p>two</p></div><div><input><p>three</p></div><!---->`,
|
||||
test ( assert, component, target, window ) {
|
||||
const inputs = [ ...target.querySelectorAll( 'input' ) ];
|
||||
|
||||
html: `
|
||||
<div>
|
||||
<input><p>one</p>
|
||||
</div>
|
||||
<div>
|
||||
<input><p>two</p>
|
||||
</div>
|
||||
<div>
|
||||
<input><p>three</p>
|
||||
</div>
|
||||
`,
|
||||
|
||||
ssrHtml: `
|
||||
<div>
|
||||
<input value=one><p>one</p>
|
||||
</div>
|
||||
<div>
|
||||
<input value=two><p>two</p>
|
||||
</div>
|
||||
<div>
|
||||
<input value=three><p>three</p>
|
||||
</div>
|
||||
`,
|
||||
|
||||
test(assert, component, target, window) {
|
||||
const inputs = [...target.querySelectorAll('input')];
|
||||
const items = component.get().items;
|
||||
const event = new window.Event( 'input' );
|
||||
const event = new window.Event('input');
|
||||
|
||||
assert.equal( inputs[0].value, 'one' );
|
||||
assert.equal(inputs[0].value, 'one');
|
||||
|
||||
inputs[1].value = 'four';
|
||||
inputs[1].dispatchEvent( event );
|
||||
inputs[1].dispatchEvent(event);
|
||||
|
||||
assert.equal( items[1], 'four' );
|
||||
assert.equal( target.innerHTML, `<div><input><p>one</p></div><div><input><p>four</p></div><div><input><p>three</p></div><!---->` );
|
||||
assert.equal(items[1], 'four');
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>
|
||||
<input><p>one</p>
|
||||
</div>
|
||||
<div>
|
||||
<input><p>four</p>
|
||||
</div>
|
||||
<div>
|
||||
<input><p>three</p>
|
||||
</div>
|
||||
`);
|
||||
|
||||
items[2] = 'five';
|
||||
|
||||
component.set({ items });
|
||||
assert.equal( inputs[2].value, 'five' );
|
||||
assert.equal( target.innerHTML, `<div><input><p>one</p></div><div><input><p>four</p></div><div><input><p>five</p></div><!---->` );
|
||||
}
|
||||
assert.equal(inputs[2].value, 'five');
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>
|
||||
<input><p>one</p>
|
||||
</div>
|
||||
<div>
|
||||
<input><p>four</p>
|
||||
</div>
|
||||
<div>
|
||||
<input><p>five</p>
|
||||
</div>
|
||||
`);
|
||||
},
|
||||
};
|
||||
|
@ -1,29 +1,43 @@
|
||||
export default {
|
||||
data: {
|
||||
user: {
|
||||
name: 'alice'
|
||||
}
|
||||
name: 'alice',
|
||||
},
|
||||
},
|
||||
|
||||
html: `
|
||||
<input>
|
||||
<p>hello alice</p>
|
||||
`,
|
||||
|
||||
html: `<input>\n<p>hello alice</p>`,
|
||||
ssrHtml: `
|
||||
<input value=alice>
|
||||
<p>hello alice</p>
|
||||
`,
|
||||
|
||||
test ( assert, component, target, window ) {
|
||||
const input = target.querySelector( 'input' );
|
||||
test(assert, component, target, window) {
|
||||
const input = target.querySelector('input');
|
||||
|
||||
assert.equal( input.value, 'alice' );
|
||||
assert.equal(input.value, 'alice');
|
||||
|
||||
const event = new window.Event( 'input' );
|
||||
const event = new window.Event('input');
|
||||
|
||||
input.value = 'bob';
|
||||
input.dispatchEvent( event );
|
||||
input.dispatchEvent(event);
|
||||
|
||||
assert.equal( target.innerHTML, `<input>\n<p>hello bob</p>` );
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input>
|
||||
<p>hello bob</p>
|
||||
`);
|
||||
|
||||
const user = component.get().user;
|
||||
user.name = 'carol';
|
||||
|
||||
component.set({ user });
|
||||
assert.equal( input.value, 'carol' );
|
||||
assert.equal( target.innerHTML, `<input>\n<p>hello carol</p>` );
|
||||
}
|
||||
assert.equal(input.value, 'carol');
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<input>
|
||||
<p>hello carol</p>
|
||||
`);
|
||||
},
|
||||
};
|
||||
|
@ -1,10 +1,24 @@
|
||||
export default {
|
||||
nestedTransitions: true,
|
||||
|
||||
html: '<div>A wild component appears</div><p>x</p><input type="text">',
|
||||
html: `
|
||||
<div>A wild component appears</div>
|
||||
<p>x</p>
|
||||
<input type=text>
|
||||
`,
|
||||
|
||||
ssrHtml: `
|
||||
<div>A wild component appears</div>
|
||||
<p>x</p>
|
||||
<input type=text value=x>
|
||||
`,
|
||||
|
||||
test(assert, component, target) {
|
||||
component.set({ x: 'y' });
|
||||
assert.htmlEqual(target.innerHTML, '<div>A wild component appears</div><p>y</p><input type="text">');
|
||||
assert.htmlEqual(target.innerHTML, `
|
||||
<div>A wild component appears</div>
|
||||
<p>y</p>
|
||||
<input type=text>
|
||||
`);
|
||||
},
|
||||
};
|
||||
|
@ -0,0 +1 @@
|
||||
<input value='bar'>
|
@ -0,0 +1,8 @@
|
||||
<input bind:value=foo >
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return { foo: 'bar' };
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in new issue