Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/warnUsingHooksOutsideRender
- Loading branch information
Showing
21 changed files
with
351 additions
and
56 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
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
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
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,72 @@ | ||
import { h, render, options } from 'preact'; | ||
import { setupScratch, teardown } from '../../../test/_util/helpers'; | ||
import { useDebugValue, useState } from '../../src'; | ||
|
||
/** @jsx h */ | ||
|
||
describe('useDebugValue', () => { | ||
|
||
/** @type {HTMLDivElement} */ | ||
let scratch; | ||
|
||
beforeEach(() => { | ||
scratch = setupScratch(); | ||
}); | ||
|
||
afterEach(() => { | ||
teardown(scratch); | ||
delete options.useDebugValue; | ||
}); | ||
|
||
it('should do nothing when no options hook is present', () => { | ||
function useFoo() { | ||
useDebugValue('foo'); | ||
return useState(0); | ||
} | ||
|
||
function App() { | ||
let [v] = useFoo(); | ||
return <div>{v}</div>; | ||
} | ||
|
||
expect(() => render(<App />, scratch)).to.not.throw(); | ||
}); | ||
|
||
it('should call options hook with value', () => { | ||
let spy = options.useDebugValue = sinon.spy(); | ||
|
||
function useFoo() { | ||
useDebugValue('foo'); | ||
return useState(0); | ||
} | ||
|
||
function App() { | ||
let [v] = useFoo(); | ||
return <div>{v}</div>; | ||
} | ||
|
||
render(<App />, scratch); | ||
|
||
expect(spy).to.be.calledOnce; | ||
expect(spy).to.be.calledWith('foo'); | ||
}); | ||
|
||
it('should apply optional formatter', () => { | ||
let spy = options.useDebugValue = sinon.spy(); | ||
|
||
function useFoo() { | ||
useDebugValue('foo', x => x + 'bar'); | ||
return useState(0); | ||
} | ||
|
||
function App() { | ||
let [v] = useFoo(); | ||
return <div>{v}</div>; | ||
} | ||
|
||
render(<App />, scratch); | ||
|
||
expect(spy).to.be.calledOnce; | ||
expect(spy).to.be.calledWith('foobar'); | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.