Skip to content

Instantly share code, notes, and snippets.

View khaosdoctor's full-sized avatar
💎
Just do things

Lucas Santos khaosdoctor

💎
Just do things
View GitHub Profile
@khaosdoctor
khaosdoctor / dummy.js
Created July 12, 2017 02:18
Dummy example
var TaskManager = function(){
var taskList = [];
return {
addTask: function(task){
taskList.push(task);
},
tasksCount: function(){
return taskList.length;
}
@khaosdoctor
khaosdoctor / faker.js
Created July 12, 2017 02:23
Faker example
var xhr, requests;
before(function {
xhr = sinon.useFakeXMLHttpRequest();
requests = [];
xhr.onCreate = function (req) { requests.push(req); };
});
after(function () {
xhr.restore(); // Limpa o objeto quando estamos trabalhando com globais
@khaosdoctor
khaosdoctor / faketimer.js
Created July 12, 2017 02:26
Fake timer example
{
setUp: function () {
this.clock = sinon.useFakeTimers();
},
tearDown: function () {
this.clock.restore();
},
describe('Deve usar um timmer de 510ms fixo', (assert) => {
@khaosdoctor
khaosdoctor / mochaDesc.js
Created July 12, 2017 02:39
Mocha test description
var assert = require('assert');
describe('Array', function() {
describe('#indexOf()', function() {
it('should return -1 when the value is not present', function() {
assert.equal(-1, [1,2,3].indexOf(4));
});
});
})
@khaosdoctor
khaosdoctor / avaDesc.js
Created July 12, 2017 02:39
Ava test description
var assert = require('assert');
describe('Route', function() {
describe('Status test', function() {
it('Should return 200 when both the database and the API are ok',
function() { //Nosso teste }
);
it('Should return 503 when the database or the API are offline',
function() { //Nosso teste }
);
});
@khaosdoctor
khaosdoctor / failTest.js
Created July 12, 2017 02:46
Failure Test for status API
describe('Should return 503 when the api or the database are not ok', (assert) => {
assert.plan(1)
let dbMock = { // Cria um modelo do objeto do banco de dados apenas com as propriedades que a rota chama
connection: {
readyState: 0
}
}
func(assert.context.routeContext, null, dbMock)
elem.style.display = ‘none’;
elem.style.display = ‘’;
elem.textContent = ‘Texto’;
elem.style.<seu estilo> = ‘’;
elem.innerHTML = ‘'
$(elem).hide();
$(elem).show();
$(elem).text();
$(elem).css();
$(elem).html();
@khaosdoctor
khaosdoctor / XHR.js
Last active September 3, 2017 16:38
var counter = 0
function ajax() {
let xhr = new XMLHttpRequest()
// Abre a conexão para a página
xhr.open(‘GET’, ‘<URL>’)
xhr.onreadystatechange = () => {
counter += 20 // 20% pois são 5 estados
if (xhr.readystate === 4 && xhr.status === 200) {
console.log(xhr.responseText) // Aqui você tem sua resposta
}
var request = new XMLHttpRequest();
request.open(‘GET’, ‘/my/url’, true);
request.onload = function() {
if (this.status >= 200 && this.status < 400) {
// Sucesso!
var resp = this.response;
} else {
// Alcançamos o servidor, mas tivemos um erro
}