From b94f03b57edb2b488ecf9cca402505a00578b84d Mon Sep 17 00:00:00 2001
From: nobkd <44443899+nobkd@users.noreply.github.com>
Date: Tue, 7 May 2024 00:25:32 +0200
Subject: [PATCH 1/2] fix: zero setAttribute
---
packages/nuejs/src/render.js | 2 +-
packages/nuejs/test/render.test.js | 16 ++++++++--------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/packages/nuejs/src/render.js b/packages/nuejs/src/render.js
index 4bcf9119..70e56678 100644
--- a/packages/nuejs/src/render.js
+++ b/packages/nuejs/src/render.js
@@ -56,7 +56,7 @@ function toString(val) {
function setAttribute(key, attribs, data) {
let val = attribs[key]
- if (!val) return
+ if (val === null || val === undefined) return
// TODO: check all non-strings here
if (val.constructor === Object) return
diff --git a/packages/nuejs/test/render.test.js b/packages/nuejs/test/render.test.js
index 136082c8..573a1119 100644
--- a/packages/nuejs/test/render.test.js
+++ b/packages/nuejs/test/render.test.js
@@ -101,14 +101,14 @@ test('Loops', () => {
'
{ i }: { key } = { value }
':
'0: name = Nick
1: email = nick@acme.org
2: age = 10
',
- '{ i }. { name }
' : '0. John
1. Alice
',
+ '{ i }. { name }
': '0. John
1. Alice
',
// loop custom tag
- ' { value }' :
+ ' { value }':
'JohnAlice',
// loop slots
- '{ el.age }{name}: ' :
+ '{ el.age }{name}: ':
'John: 22Alice: 33',
// successive loops
@@ -116,7 +116,7 @@ test('Loops', () => {
'',
}, {
- items: [ { name: 'John', age: 22 }, { name: 'Alice', age: 33 }],
+ items: [{ name: 'John', age: 22 }, { name: 'Alice', age: 33 }],
person: { name: 'Nick', email: 'nick@acme.org', age: 10 },
nums: [-1, 0, 1],
})
@@ -144,7 +144,7 @@ test('Advanced', () => {
runTests({
// :attr (:bind works the same on server side)
- '': '',
+ '': '',
'': '\n \n
',
@@ -156,10 +156,10 @@ test('Advanced', () => {
'',
}, {
- person: { name: 'Nick', age: 10 },
+ person: { name: 'Nick', age: 0 },
page: 'Hello',
nums: [1, 2],
- val: 1
+ val: 1,
})
})
@@ -232,7 +232,7 @@ const IF_SIBLING = `
`
test('If sibling', () => {
- const els = [{ label: 'First'}]
+ const els = [{ label: 'First' }]
const html = render(IF_SIBLING, { els })
expect(html).toInclude('First')
})
From b918eb2d25a0908ad4716d99bfe100eee903dde4 Mon Sep 17 00:00:00 2001
From: nobkd <44443899+nobkd@users.noreply.github.com>
Date: Tue, 7 May 2024 00:25:46 +0200
Subject: [PATCH 2/2] test: falsy data
---
packages/nuejs/test/render.test.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/packages/nuejs/test/render.test.js b/packages/nuejs/test/render.test.js
index 573a1119..43c895a9 100644
--- a/packages/nuejs/test/render.test.js
+++ b/packages/nuejs/test/render.test.js
@@ -115,10 +115,12 @@ test('Loops', () => {
'':
'',
+ '{el}': 'false0NaN'
}, {
items: [{ name: 'John', age: 22 }, { name: 'Alice', age: 33 }],
person: { name: 'Nick', email: 'nick@acme.org', age: 10 },
nums: [-1, 0, 1],
+ falsy: ['', false, 0, NaN, null, undefined],
})
})