diff --git a/src/api/manipulation.spec.ts b/src/api/manipulation.spec.ts index c3134222fe..d11d8d981a 100644 --- a/src/api/manipulation.spec.ts +++ b/src/api/manipulation.spec.ts @@ -1901,6 +1901,11 @@ describe('$(...)', () => { expect(text).toBe('M&M'); }); + it('should turn passed values to strings', () => { + $('.apple').text(1 as any); + expect($('.apple')[0].childNodes[0]).toHaveProperty('data', '1'); + }); + it('( undefined ) : should act as an accessor', () => { const $div = $('
test
'); expect(typeof $div.text(undefined as any)).toBe('string'); diff --git a/src/api/manipulation.ts b/src/api/manipulation.ts index 21d3552a71..dbfcf349d1 100644 --- a/src/api/manipulation.ts +++ b/src/api/manipulation.ts @@ -1004,7 +1004,7 @@ export function text( child.next = child.prev = child.parent = null; }); - const textNode = new Text(str); + const textNode = new Text(`${str}`); updateDOM(textNode, el); });