This file contains hidden or 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
| import { renderHook, act } from "react-hooks-testing-library"; | |
| jest.mock("axios"); | |
| describe("useRandomUsers", () => { | |
| it("call API and return results", async () => { | |
| axios.mockImplementation(() => Promise.resolve({ data: mockResponse })); | |
| const { result, waitForNextUpdate } = renderHook(() => useRandomUsers()); | |
| expect(result.current).toStrictEqual([]); |
This file contains hidden or 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
| jest.mock("axios"); | |
| describe("useRandomUsers", () => { | |
| it("call API and return results", async () => { | |
| axios.mockImplementation(() => Promise.resolve({ data: mockResponse })); | |
| const users = useRandomUsers(); | |
| expect(users.current).toStrictEqual(mockResponse); | |
| }); | |
| }); |
This file contains hidden or 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
| const App = () => { | |
| const users = useRandomUsers(); | |
| return ( | |
| <div className="App"> | |
| <header className="App-header"> | |
| <ol> | |
| {users && | |
| users.map(({ name, login }) => ( | |
| <li key={login.uuid}> |
This file contains hidden or 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
| const App = () => { | |
| const [users, setUsers] = useState([]); | |
| useEffect(() => { | |
| (async () => { | |
| try { | |
| const response = await axios( | |
| "https://randomuser.me/api/?results=10&inc=name,login&nat=us" | |
| ); | |
| setUsers(response.data.results); |
This file contains hidden or 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
| class App extends React.Component { | |
| state = { users: [] }; | |
| componentDidMount() { | |
| axios("https://randomuser.me/api/?results=10&inc=name,login&nat=us").then( | |
| response => { | |
| this.setState({ | |
| users: response.data.results | |
| }); | |
| } |
This file contains hidden or 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
| // apm list --installed --bare > atom-package-list.txt | |
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] | |
| [email protected] |
This file contains hidden or 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
| const animals = [ | |
| { | |
| "name": "cat", | |
| "size": "small", | |
| "weight": 5 | |
| }, | |
| { | |
| "name": "dog", | |
| "size": "small", | |
| "weight": 10 |
This file contains hidden or 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
| const proto = { | |
| hello: function hello() { | |
| return `Hello, my name is ${ this.name }`; | |
| } | |
| }; | |
| const george = Object.assign({}, proto, {name: 'George'}); | |
| const msg = george.hello(); |
This file contains hidden or 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
| /** | |
| * Simulate classical ineritance (not recommended) using constructor function | |
| */ | |
| function Greeter (name) { | |
| this.name = name || 'John Doe'; | |
| } | |
| Greeter.prototype.hello = function hello () { | |
| return 'Hello, my name is ' + this.name; |
This file contains hidden or 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
| var fibonacci = function(number) { | |
| var mem = {}; | |
| function f(n) { | |
| var value; | |
| if (n in mem) { | |
| value = mem[n]; | |
| } | |
| else { |
NewerOlder