From 24424cf8399636ef913cf026b290bff428fe4bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=B4=E6=BE=9C?= Date: Mon, 13 Jul 2020 16:54:59 +0800 Subject: [PATCH] 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 --- packages/driver-dom/package.json | 2 +- .../driver-dom/src/__tests__/attributes.js | 105 ++++++++++++++++++ packages/driver-dom/src/__tests__/svg.js | 18 +++ packages/driver-dom/src/index.js | 7 +- 4 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 packages/driver-dom/src/__tests__/attributes.js diff --git a/packages/driver-dom/package.json b/packages/driver-dom/package.json index 3172ba1b1e..dca467025d 100644 --- a/packages/driver-dom/package.json +++ b/packages/driver-dom/package.json @@ -1,6 +1,6 @@ { "name": "driver-dom", - "version": "2.1.0", + "version": "2.1.1", "description": "DOM driver for Rax", "license": "BSD-3-Clause", "main": "lib/index.js", diff --git a/packages/driver-dom/src/__tests__/attributes.js b/packages/driver-dom/src/__tests__/attributes.js new file mode 100644 index 0000000000..107886e90c --- /dev/null +++ b/packages/driver-dom/src/__tests__/attributes.js @@ -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(( +
+ ), container, { + driver: DriverDOM + }); + + let node = container.children[0]; + expect(node.getAttribute('width')).toBe('30'); + }); + + it('render string prop with true value', () => { + render(( + + ), container, { + driver: DriverDOM + }); + + let node = container.children[0]; + expect(node.getAttribute('href')).toBe('true'); + }); + + it('render string prop with object value', () => { + render(( + + ), 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(( +