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 cursor = db.collection('Movies').find().map(value => ({ | |
value, | |
done: !value | |
})); | |
for await (const doc of cursor) { | |
console.log(doc.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
const bcrypt = require('bcrypt'); | |
const NUM_SALT_ROUNDS = 8; | |
test(); | |
async function test() { | |
const pws = ['password', 'password1', 'passw0rd']; | |
// `promises` é uma array de Promises, porque `bcrypt.hash()` |
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
/** | |
* Irá printar abaixo: | |
* esperando... 250 | |
* resolvido com 250 | |
* esperando... 500 | |
* esperando... 1000 | |
*/ | |
test(); | |
async function test() { |
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 Form extends TraditionalObjectOrientedView { | |
render() { | |
// Informações passadas | |
const { isSubmitted, buttonText } = this.attrs; | |
if (!isSubmitted && !this.button) { | |
// Form não foi enviado ainda | |
this.button = new Button({ | |
children: buttonText, | |
color: 'blue' | |
}); |
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 renderer from 'react-test-renderer' | |
import Select from '../Select' | |
jest.mock('react-select', () => { | |
const { createElement } = require('react') | |
// Perceba que como estamos mockando 'react-select' | |
// nós precisamos usar require.requireActual, dentro do nosso mock | |
// A melhor analogia aqui é o filme Inception, naquela parte do | |
// sonho dentro do sonho, espero que você tenha assistido! :P | |
const ReactSelect = require.requireActual('react-select') |
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 renderer from 'react-test-renderer' | |
import Header from '../Header' | |
import store from '../store' | |
jest.mock('react-redux-loading-bar', () => { | |
const ReactReduxLoadingBar = require.requireActual('react-redux-loading-bar') | |
return { | |
// Operação "spread" do módulo original | |
...ReactReduxLoadingBar, |
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 renderer from 'react-test-renderer' | |
import App from '../App' | |
jest.mock('react-router-dom', () => ({ | |
Link: 'Link', | |
Route: ({ children, ...props }) => | |
typeof children === 'function' | |
? children({ match: path === '/somewhere' }) | |
: createElement('Route', props) | |
})) |
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 renderer from 'react-test-renderer' | |
import App from '../App' | |
// O snapshot gerado é extamente igual ao exemplo anterior | |
// É possível sobrescrever o nosso mock padrão | |
// usando o mesmo método jest.mock, caso esse teste | |
// precise de um comportamento diferente | |
it('should render correctly', () => { | |
const component = renderer.create(<App />) |
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": { | |
"setupFiles": [ | |
"<rootDir>/test-setup.js" | |
] | |
} | |
} |