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
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 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 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 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 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 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 | |
angularjs@0.4.0 | |
atom-beautify@0.30.3 | |
atom-grails@1.0.1 | |
atom-material-syntax@1.0.6 | |
atom-material-ui@2.0.4 | |
auto-detect-indentation@1.3.0 | |
autoclose-html@0.23.0 | |
busy-signal@1.4.3 | |
docblockr@0.10.5 |
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
const animals = [ | |
{ | |
"name": "cat", | |
"size": "small", | |
"weight": 5 | |
}, | |
{ | |
"name": "dog", | |
"size": "small", | |
"weight": 10 |
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
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 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 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