|
@@ -101,6 +101,9 @@ test('x-model casts value to boolean if boolean modifier is present',
|
|
|
html`
|
|
|
<div x-data="{ foo: null, bar: null, baz: [] }">
|
|
|
<input type="text" x-model.boolean="foo"></input>
|
|
|
+ <input type="checkbox" x-model.boolean="foo"></input>
|
|
|
+ <input type="radio" name="foo" x-model.boolean="foo" value="true"></input>
|
|
|
+ <input type="radio" name="foo" x-model.boolean="foo" value="false"></input>
|
|
|
<select x-model.boolean="bar">
|
|
|
<option value="true">yes</option>
|
|
|
<option value="false">no</option>
|
|
@@ -110,20 +113,24 @@ test('x-model casts value to boolean if boolean modifier is present',
|
|
|
({ get }) => {
|
|
|
get('input[type=text]').type('1')
|
|
|
get('div').should(haveData('foo', true))
|
|
|
-
|
|
|
get('input[type=text]').clear().type('0')
|
|
|
get('div').should(haveData('foo', false))
|
|
|
|
|
|
- get('input[type=text]').clear().type('true')
|
|
|
+ get('input[type=checkbox]').check()
|
|
|
get('div').should(haveData('foo', true))
|
|
|
+ get('input[type=checkbox]').uncheck()
|
|
|
+ get('div').should(haveData('foo', false))
|
|
|
|
|
|
- get('input[type=text]').clear().type('false')
|
|
|
+ get('input[type=radio][value="true"]').should(notBeChecked())
|
|
|
+ get('input[type=radio][value="false"]').should(beChecked())
|
|
|
+ get('input[type=radio][value="true"]').check()
|
|
|
+ get('div').should(haveData('foo', true))
|
|
|
+ get('input[type=radio][value="false"]').check()
|
|
|
get('div').should(haveData('foo', false))
|
|
|
|
|
|
- get('select').select('no')
|
|
|
+ get('select').select('false')
|
|
|
get('div').should(haveData('bar', false))
|
|
|
-
|
|
|
- get('select').select('yes')
|
|
|
+ get('select').select('true')
|
|
|
get('div').should(haveData('bar', true))
|
|
|
}
|
|
|
)
|
|
@@ -138,7 +145,7 @@ test('x-model with boolean modifier returns: null if empty, original value if ca
|
|
|
get('input').clear()
|
|
|
get('div').should(haveData('foo', null))
|
|
|
get('input').clear().type('bar')
|
|
|
- get('div').should(haveData('foo', 'bar'))
|
|
|
+ get('div').should(haveData('foo', true))
|
|
|
get('input').clear().type('1')
|
|
|
get('div').should(haveData('foo', true))
|
|
|
get('input').clear().type('1').clear()
|
|
@@ -146,7 +153,7 @@ test('x-model with boolean modifier returns: null if empty, original value if ca
|
|
|
get('input').clear().type('0')
|
|
|
get('div').should(haveData('foo', false))
|
|
|
get('input').clear().type('bar')
|
|
|
- get('div').should(haveData('foo', 'bar'))
|
|
|
+ get('div').should(haveData('foo', true))
|
|
|
get('input').clear().type('0').clear()
|
|
|
get('div').should(haveData('foo', null))
|
|
|
}
|