This file contains hidden or 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 mongodb = require('mongodb'); | |
test(); | |
async function test() { | |
const db = await mongodb.MongoClient.connect('mongodb://localhost:27017/test'); | |
await db.collection('Movies').drop(); | |
await db.collection('Movies').insertMany([ | |
{ name: 'Enter the Dragon' }, |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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, |