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 walkDOMTree( | |
root, | |
whatToShow = NodeFilter.SHOW_ALL, | |
{ inspect, collect, callback } = {} | |
) { | |
const walker = document.createTreeWalker(root, whatToShow, { | |
acceptNode(node) { | |
if (inspect && !inspect(node)) { | |
return NodeFilter.FILTER_REJECT; | |
} |
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 {mockFetchResponse} from 'test-utils/mock-fetch-response'; | |
test(`logging in displays the user's username`, async () => { | |
const {mockSuccessResponse, fetchPromise} = mockFetchResponse(); | |
window.fetch = jest.fn().mockReturnValueOnce(fetchPromise); | |
render(<Login />) | |
const {username, password} = buildLoginForm() | |
userEvent.type(screen.getByLabelText(/username/i), username) | |
userEvent.type(screen.getByLabelText(/password/i), password) |
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.exports = { | |
env: { | |
browser: true, | |
es2021: true, | |
node: true, | |
}, | |
extends: [ | |
'plugin:react/recommended', | |
'plugin:prettier/recommended', | |
'plugin:react-hooks/recommended', |
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
{ | |
"printWidth": 160, | |
"tabWidth": 2, | |
"useTabs": false, | |
"semi": true, | |
"singleQuote": true, | |
"trailingComma": "es5", | |
"bracketSpacing": true, | |
"jsxBracketSameLine": false, | |
"arrowParens": "always" |
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 withStateSlice(Comp, slice) { | |
const MemoComp = React.memo(Comp); | |
function Wrapper(props, ref) { | |
const state = useAppState(); | |
const cell = slice(state, props); | |
return <MemoComp ref={ref} state={cell} {...props} />; | |
} | |
Wrapper.displayName = `withStateSlice(${Comp.displayName || Comp.name})`; | |
return React.memo(React.forwardRef(Wrapper)); | |
} |
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
Show hidden characters
{ | |
"presets": [ | |
"env" | |
] | |
} |
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 capitalize = require('./index'); | |
test('Capitalize is a function', () => { | |
expect(typeof capitalize).toEqual('function'); | |
}); | |
test('capitalizes the first letter of every word in a sentence', () => { | |
expect(capitalize('hi there, how is it going?')).toEqual( | |
'Hi There, How Is It Going?' | |
); |
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
{ | |
"singleQuote": true, | |
"useTabs": true, | |
"tabWidth": 2, | |
"trailingComma": "es5", | |
"endOfLine": "lf", | |
"printWidth": 80, | |
"semi": true | |
} |
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
// We declare our mapper function, context aware | |
function mapProductId(transactionsArray) { | |
return transactionsArray | |
.map(transaction => ({ | |
...transaction, | |
productId: this.getProductId(transaction.id) | |
})) | |
} | |
// And now, we can transform our data like so |
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 response3 = [ | |
{ purchaseId: 21, productName: 'Bag' }, | |
{ purchaseId: 22, productName: 'Lamp' }, | |
]; | |
const requiredOutput3 = [ | |
{ productId: 31, purchaseId: 21, product: { name: 'Bag' } }, | |
{ productId: 32, purchaseId: 22, product: { name: 'Lamp' } }, | |
]; |
NewerOlder