-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: failure to set attribute by DOM properties (#1923)
* fix: failure to set attribute by DOM properties * v2.0.10 * test: for attributes * fix: require to setAttribute for svg nodes * fix: test for render boolean prop * chore: comment for svg prop
- Loading branch information
1 parent
a97c11a
commit 24424cf
Showing
4 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { createElement, render } from 'rax'; | ||
import * as DriverDOM from '../'; | ||
|
||
describe('attributes', () => { | ||
let container; | ||
|
||
beforeEach(() => { | ||
container = document.createElement('div'); | ||
(document.body || document.documentElement).appendChild(container); | ||
}); | ||
|
||
describe('string properties', () => { | ||
it('render string prop with simple numbers', () => { | ||
render(( | ||
<div width={30} /> | ||
), container, { | ||
driver: DriverDOM | ||
}); | ||
|
||
let node = container.children[0]; | ||
expect(node.getAttribute('width')).toBe('30'); | ||
}); | ||
|
||
it('render string prop with true value', () => { | ||
render(( | ||
<a href={true} /> | ||
), container, { | ||
driver: DriverDOM | ||
}); | ||
|
||
let node = container.children[0]; | ||
expect(node.getAttribute('href')).toBe('true'); | ||
}); | ||
|
||
it('render string prop with object value', () => { | ||
render(( | ||
<input type="checkbox" data={{foo: 'bar'}} /> | ||
), container, { | ||
driver: DriverDOM | ||
}); | ||
|
||
let node = container.children[0]; | ||
expect(node.getAttribute('data')).toBe('[object Object]'); | ||
}); | ||
}); | ||
|
||
describe('boolean properties', () => { | ||
it('render boolean prop with true value', () => { | ||
render(( | ||
<div hidden={true} /> | ||
), container, { | ||
driver: DriverDOM | ||
}); | ||
|
||
let node = container.children[0]; | ||
expect(node.getAttribute('hidden')).toBe(''); | ||
}); | ||
|
||
it('render boolean prop with false value', () => { | ||
render(( | ||
<div hidden={false} /> | ||
), container, { | ||
driver: DriverDOM | ||
}); | ||
|
||
let node = container.children[0]; | ||
expect(node.getAttribute('hidden')).toBe(null); | ||
}); | ||
|
||
it('render boolean prop with self value', () => { | ||
render(( | ||
<div hidden={'hidden'} /> | ||
), container, { | ||
driver: DriverDOM | ||
}); | ||
|
||
let node = container.children[0]; | ||
expect(node.getAttribute('hidden')).toBe(''); | ||
}); | ||
}); | ||
|
||
describe('properties must set with property', () => { | ||
it('render boolean prop with true', () => { | ||
render(( | ||
<input type="checkbox" checked={true} /> | ||
), container, { | ||
driver: DriverDOM | ||
}); | ||
|
||
let node = container.children[0]; | ||
expect(node.checked).toBe(true); | ||
}); | ||
|
||
it('render boolean prop with false', () => { | ||
render(( | ||
<input type="checkbox" checked={false} /> | ||
), container, { | ||
driver: DriverDOM | ||
}); | ||
|
||
let node = container.children[0]; | ||
expect(node.checked).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters