From 38acabfa6089ab8ac469c12b5f55022fb96935e5 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 23 Aug 2021 16:46:06 -0300 Subject: added web vendors --- preact/hooks/test/browser/useRef.test.js | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 preact/hooks/test/browser/useRef.test.js (limited to 'preact/hooks/test/browser/useRef.test.js') diff --git a/preact/hooks/test/browser/useRef.test.js b/preact/hooks/test/browser/useRef.test.js new file mode 100644 index 0000000..7d7a657 --- /dev/null +++ b/preact/hooks/test/browser/useRef.test.js @@ -0,0 +1,50 @@ +import { createElement, render } from 'preact'; +import { setupScratch, teardown } from '../../../test/_util/helpers'; +import { useRef } from 'preact/hooks'; + +/** @jsx createElement */ + +describe('useRef', () => { + /** @type {HTMLDivElement} */ + let scratch; + + beforeEach(() => { + scratch = setupScratch(); + }); + + afterEach(() => { + teardown(scratch); + }); + + it('provides a stable reference', () => { + const values = []; + + function Comp() { + const ref = useRef(1); + values.push(ref.current); + ref.current = 2; + return null; + } + + render(, scratch); + render(, scratch); + + expect(values).to.deep.equal([1, 2]); + }); + + it('defaults to undefined', () => { + const values = []; + + function Comp() { + const ref = useRef(); + values.push(ref.current); + ref.current = 2; + return null; + } + + render(, scratch); + render(, scratch); + + expect(values).to.deep.equal([undefined, 2]); + }); +}); -- cgit v1.2.3