mirror of https://github.com/sveltejs/svelte
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
8 years ago
|
export default {
|
||
|
data: {
|
||
|
items: [
|
||
|
{ description: 'one', completed: true },
|
||
|
{ description: 'two', completed: false },
|
||
|
{ description: 'three', completed: false }
|
||
|
]
|
||
|
},
|
||
8 years ago
|
|
||
|
html: `
|
||
|
<div><input type="checkbox"><p>one</p></div><div><input type="checkbox"><p>two</p></div><div><input type="checkbox"><p>three</p></div>
|
||
|
<p>1 completed</p>
|
||
|
`,
|
||
|
|
||
8 years ago
|
test ( assert, component, target, window ) {
|
||
8 years ago
|
const inputs = [ ...target.querySelectorAll( 'input' ) ];
|
||
|
|
||
|
assert.ok( inputs[0].checked );
|
||
|
assert.ok( !inputs[1].checked );
|
||
|
assert.ok( !inputs[2].checked );
|
||
|
|
||
|
const event = new window.Event( 'change' );
|
||
|
|
||
|
inputs[1].checked = true;
|
||
|
inputs[1].dispatchEvent( event );
|
||
|
|
||
|
assert.equal( component.get( 'numCompleted' ), 2 );
|
||
8 years ago
|
assert.htmlEqual( target.innerHTML, `
|
||
|
<div><input type="checkbox"><p>one</p></div><div><input type="checkbox"><p>two</p></div><div><input type="checkbox"><p>three</p></div>
|
||
|
<p>2 completed</p>
|
||
|
` );
|
||
8 years ago
|
|
||
|
const items = component.get( 'items' );
|
||
|
items[2].completed = true;
|
||
|
|
||
|
component.set({ items });
|
||
|
assert.ok( inputs[2].checked );
|
||
8 years ago
|
assert.htmlEqual( target.innerHTML, `
|
||
|
<div><input type="checkbox"><p>one</p></div><div><input type="checkbox"><p>two</p></div><div><input type="checkbox"><p>three</p></div>
|
||
|
<p>3 completed</p>
|
||
|
` );
|
||
8 years ago
|
}
|
||
|
};
|