Skip to content

Instantly share code, notes, and snippets.

View ivan-ha's full-sized avatar
👨‍💻
cannot read property 'status' of undefined 😄

Ivan Ha ivan-ha

👨‍💻
cannot read property 'status' of undefined 😄
View GitHub Profile
@ivan-ha
ivan-ha / useRandomUsers.test.js
Last active June 1, 2019 13:00
react-hooks-test-custom-hooks
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([]);
@ivan-ha
ivan-ha / useRandomUsers.test.js
Created June 1, 2019 10:00
react-hooks-test-failed-unit-test
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);
});
});
@ivan-ha
ivan-ha / app.js
Created June 1, 2019 07:57
react-hooks-test-custom-hooks
const App = () => {
const users = useRandomUsers();
return (
<div className="App">
<header className="App-header">
<ol>
{users &&
users.map(({ name, login }) => (
<li key={login.uuid}>
@ivan-ha
ivan-ha / app.js
Created June 1, 2019 07:49
react-hooks-test-using-hooks
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);
@ivan-ha
ivan-ha / app.js
Last active June 1, 2019 07:48
react-hooks-test-traditional-way
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
});
}
// 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
@ivan-ha
ivan-ha / map-filter-reduce.js
Last active June 26, 2017 03:36
Simple note on map, filter and reduce on JS
const animals = [
{
"name": "cat",
"size": "small",
"weight": 5
},
{
"name": "dog",
"size": "small",
"weight": 10
@ivan-ha
ivan-ha / greeter-concatenative.js
Created April 6, 2017 02:02
JS Concatenative Inheritance
const proto = {
hello: function hello() {
return `Hello, my name is ${ this.name }`;
}
};
const george = Object.assign({}, proto, {name: 'George'});
const msg = george.hello();
/**
* 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;
var fibonacci = function(number) {
var mem = {};
function f(n) {
var value;
if (n in mem) {
value = mem[n];
}
else {