forked from cypress-io/cypress-react-unit-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding tests for React.memo * Adding tests for React.forwardRef * Adding basic hook tests
- Loading branch information
atomicpages
committed
May 22, 2019
1 parent
fc07009
commit 5140ac5
Showing
8 changed files
with
141 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/// <reference types="cypress" /> | ||
/// <reference types="../../lib" /> | ||
|
||
import React from 'react' | ||
import CounterWithHooks from '../../src/counter-with-hooks.jsx' | ||
|
||
/* eslint-env mocha */ | ||
describe('CounterWithHooks component', function () { | ||
it('works', function () { | ||
cy.mount(<CounterWithHooks initialCount={3} />) | ||
cy.contains('3') | ||
}) | ||
}) |
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,21 @@ | ||
/// <reference types="cypress" /> | ||
/// <reference types="../../lib" /> | ||
|
||
import React from 'react' | ||
import Button from '../../src/forward-ref.jsx' | ||
|
||
/* eslint-env mocha */ | ||
describe('Button component', function () { | ||
it('works', function () { | ||
cy.mount(<Button>Hello, World</Button>) | ||
cy.contains('Hello, World') | ||
}) | ||
|
||
it('forwards refs as expected', function () { | ||
const ref = React.createRef(); | ||
|
||
cy.mount(<Button className="testing" ref={ref}>Hello, World</Button>); | ||
expect(ref).to.have.property('current'); | ||
// expect(ref.current).not.be.null; | ||
}) | ||
}) |
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,13 @@ | ||
/// <reference types="cypress" /> | ||
/// <reference types="../../lib" /> | ||
|
||
import React from 'react' | ||
import Button from '../../src/pure-component.jsx' | ||
|
||
/* eslint-env mocha */ | ||
describe('Button pure component', function () { | ||
it('works', function () { | ||
cy.mount(<Button>Hello</Button>) | ||
cy.contains('Hello') | ||
}) | ||
}) |
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,18 @@ | ||
import React from 'react'; | ||
|
||
export default function CounterWithHooks({ initialCount = 0 }) { | ||
const [count, setCount] = React.useState(initialCount); | ||
|
||
const handleCountIncrement = React.useCallback(() => { | ||
setCount(count + 1); | ||
}, [count]); | ||
|
||
return ( | ||
<> | ||
<div className="counter"> | ||
{count} | ||
</div> | ||
<button onClick={handleCountIncrement}>+</button> | ||
</> | ||
) | ||
} |
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,5 @@ | ||
import React from 'react'; | ||
|
||
const Button = React.forwardRef(({ children, ...rest }, ref) => <button {...rest} ref={ref}>{children}</button>); | ||
|
||
export default Button; |
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,7 @@ | ||
import React from 'react'; | ||
|
||
const Button = ({ children, ...rest }) => { | ||
return <button {...rest}>{children}</button>; | ||
}; | ||
|
||
export default React.memo(Button); |