-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve code coverage and fix lint warnings (PR #2041)
Merge pull request #2041 from preactjs/feat/improve-coverage
- Loading branch information
Showing
12 changed files
with
490 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { vnodeSpy, eventSpy } from '../../../test/_util/optionSpies'; | ||
import { render, createElement, Component, createRef } from '../../src'; | ||
import { setupRerender } from 'preact/test-utils'; | ||
import { setupScratch, teardown, createEvent } from '../../../test/_util/helpers'; | ||
|
||
/** @jsx createElement */ | ||
|
||
describe('compat options', () => { | ||
|
||
/** @type {HTMLDivElement} */ | ||
let scratch; | ||
|
||
/** @type {() => void} */ | ||
let rerender; | ||
|
||
/** @type {() => void} */ | ||
let increment; | ||
|
||
/** @type {import('../../src/index').PropRef<HTMLButtonElement | null>} */ | ||
let buttonRef; | ||
|
||
beforeEach(() => { | ||
scratch = setupScratch(); | ||
rerender = setupRerender(); | ||
|
||
vnodeSpy.resetHistory(); | ||
eventSpy.resetHistory(); | ||
|
||
buttonRef = createRef(); | ||
}); | ||
|
||
afterEach(() => { | ||
teardown(scratch); | ||
}); | ||
|
||
class ClassApp extends Component { | ||
constructor() { | ||
super(); | ||
this.state = { count: 0 }; | ||
increment = () => | ||
this.setState(({ count }) => ({ | ||
count: count + 1 | ||
})); | ||
} | ||
|
||
render() { | ||
return ( | ||
<button ref={buttonRef} onClick={increment}> | ||
{this.state.count} | ||
</button> | ||
); | ||
} | ||
} | ||
|
||
it('should call old options on mount', () => { | ||
render(<ClassApp />, scratch); | ||
|
||
expect(vnodeSpy).to.have.been.called; | ||
}); | ||
|
||
it('should call old options on event and update', () => { | ||
render(<ClassApp />, scratch); | ||
expect(scratch.innerHTML).to.equal('<button>0</button>'); | ||
|
||
buttonRef.current.dispatchEvent(createEvent('click')); | ||
rerender(); | ||
expect(scratch.innerHTML).to.equal('<button>1</button>'); | ||
|
||
expect(vnodeSpy).to.have.been.called; | ||
expect(eventSpy).to.have.been.called; | ||
}); | ||
|
||
it('should call old options on unmount', () => { | ||
render(<ClassApp />, scratch); | ||
render(null, scratch); | ||
|
||
expect(vnodeSpy).to.have.been.called; | ||
}); | ||
}); |
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.