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 { describe, it, expect, spyOn } from "bun:test"; | |
import { fetchJson } from "./fetchJson"; | |
class MockResponse { | |
static instanceCount = 0; | |
constructor( | |
public readonly ok: boolean, | |
private jsonSuccess: boolean | "bad parse", | |
) { | |
MockResponse.instanceCount++; |
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
// Current. The request is synchronous because the former needs to finish before the later | |
const earning = await fetchLastMonthEarning(teacherInfo.teacher.teacherId, startDate, endDate); | |
const teachingHours = await fetchTeachingHours(teacherInfo.teacher.teacherId); | |
// Refactored. Ensures the request is run concurrently | |
const [ earning, teachingHours ]= await Promise.all([ | |
fetchLastMonthEarning(teacherInfo.teacher.teacherId, startDate, endDate), | |
fetchTeachingHours(teacherInfo.teacher.teacherId) | |
]) |
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
// Define a setup function you can reuse and maybe nuke beforeEach completely. | |
// Your test spec is currently too simple to even require the hasle beforeEach; | |
function setUp() { | |
const props = { | |
strategy: null, | |
event: mockEvent, // You can use jest to mock | |
eventId: mockEventId, | |
ConfigLogo: null, | |
handleDuplicateEvent: action("select provider") | |
} |
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
/* | |
1) Depending on your experience, this is all you might need to do to hook up your workflow | |
2) Remember, not to copy and paste. My idea is to show you how things fit it to you can tailor it to your application | |
GRACIAS 💪 | |
*/ |
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
// Create a range of values | |
function range(start, end) { | |
return Array.apply(null, Array(end - start + 1)) | |
.map((_, index) => index + start); | |
} |
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
// getComponent is a function that returns a promise for a component | |
// It will not be called until the first mount | |
function asyncComponent(getComponent) { | |
return class AsyncComponent extends React.Component { | |
static Component = null; | |
state = { Component: AsyncComponent.Component }; | |
componentWillMount() { | |
if (!this.state.Component) { | |
getComponent().then(Component => { |
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 React from 'react'; | |
import { render } from 'react-dom'; | |
import ChildA from './childA.js'; | |
import ChildB from './childB.js'; | |
class App extends React.Component { | |
handleKeyUp() { | |
console.log('Event bubbling: Passing up data from Child to Parent component'); | |
} | |
render() { |
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
-module(assignment). | |
-export([perimeter/1, area/1, enclose/1, bit/1]). | |
% perimeter implementation | |
perimeter({circle, R}) -> | |
2 * math:pi() * R; | |
perimeter({rectangle, H, W}) -> | |
2*(H + W); |
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
function test (num) { | |
var holder = num.split(''); | |
var sum = 0, i = 0; | |
var count = holder.length; | |
while(i < count) { | |
if(holder[i] === '-'){ | |
sum = sum - holder[i + 1]; | |
i += 2; | |
} else{ | |
sum += parseInt(holder[i]); |
NewerOlder