Skip to content

Instantly share code, notes, and snippets.

View ramon-src's full-sized avatar
🎯
Focused in learn Scalable Architectures

Ramon Schmidt Rocha ramon-src

🎯
Focused in learn Scalable Architectures
View GitHub Profile
@ramon-src
ramon-src / bdd_example.rb
Created December 19, 2017 16:30
BDD example with RBehave
@given('the ninja has a {achievement_level}')
def step_the_ninja_has_a(context, achievement_level):
context.ninja_fight = NinjaFight(achievement_level)
@when('attacked by a {opponent_role}')
def step_attacked_by_a(context, opponent_role):
context.ninja_fight.opponent = opponent_role
@when('attacked by {opponent}')
def step_attacked_by(context, opponent):
@ramon-src
ramon-src / bdd_example.js
Created December 19, 2017 16:49
BDD example with Mocha
describe('TaskStack', function(){
describe('#add()', function(){
it('must have one element', function(){
const task = new Task();
const taskStack = new TaskStack();
taskStack.add(task);
taskStack.should.have.length(1);
})
})
})
@ramon-src
ramon-src / main-commands-jest-installation.sh
Last active July 20, 2018 00:35
vue-test-utils and jest npm dependencies
#To install the Jest test runner and the Vue Test Utils tool
npm install --save-dev jest @vue/test-utils
#To allow Jest to know how to work with SFC (Single File Components)
npm install --save-dev vue-jest
#To allow write Jest tests with the latests EcmaScript versions
npm install --save-dev babel-jest
@ramon-src
ramon-src / main-configuration-jest-package.json
Last active January 27, 2018 11:28
The main configurations to run npm test with jest
{
"_comment": "Many Project INFO goes here...",
"scripts": {
"_comment": "Many scripts goes here...",
"test": "jest"
},
"dependencies": {
"_comment": "Many dependencies goes here...",
},
@ramon-src
ramon-src / tdd-red-green-3.js
Created January 27, 2018 17:18
Refactoring mocking axios lib and creating a beforeAll method to mock axios in all tests with shallow, because mount is not necessary
import { shallow } from 'vue-test-utils';
import ServicePage from '@/components/Service';
const axios = {
get: (url) => {
if (url === '/') {
return Promise.resolve({
data: [
{ name: 'Ramon', status: 'true' },
{ name: 'Rodrigo', status: 'true' },
@ramon-src
ramon-src / tdd-green-1.js
Created January 27, 2018 17:30
ServicePage - Init test using TDD, only validating if component contains a list
import { mount } from 'vue-test-utils';
import ServicePage from '@/components/Service';
describe('ServicePage', () => {
it('should show the state from service', () => {
const servicePage = mount(ServicePage);
expect(servicePage.contains('.service__list')).toBe(true);
});
});
@ramon-src
ramon-src / tdd-green-vue-1.vue
Created January 27, 2018 17:38
The component created after the test tdd-green-1
<template>
<ul class="service__list">
<li></li>
</ul>
</template>
<script>
export default {
name: 'service-page',
data() {
@ramon-src
ramon-src / tdd-green-blue-1.js
Created January 27, 2018 17:42
Refactoring of tdd-green test now the method was removed and split in two others, expecting an item in the list service
import { mount } from 'vue-test-utils';
import ServicePage from '@/components/Service';
describe('ServicePage', () => {
it('should show the state from service', () => {
const servicePage = mount(ServicePage);
expect(servicePage.find('.service__list-item-status').text()).toBe('true');
});
it('should show the name from service', () => {
@ramon-src
ramon-src / tdd-green-blue-vue-1.vue
Created January 27, 2018 18:03
After refactoring of expecting an item with status and name in the tests, the component should be refactored too
<template>
<ul class="service__list">
<li v-for="(service, index) in services" :key="index"
class="service__list-item">
<span class="service__list-item-status">{{ service.status }}</span>
<span class="service__list-item-name">{{ service.name }}</span>
</li>
</ul>
</template>
@ramon-src
ramon-src / tdd-blue-1.js
Created January 27, 2018 18:13
After the first green we do the blue step, to refactor the list to show item with status and name
import { mount } from 'vue-test-utils';
import ServicePage from '@/components/Service';
describe('ServicePage', () => {
it('should show the name and the service state', () => {
const servicePage = mount(ServicePage);
expect(servicePage.find('.service__list-item-status').text()).toBe('true');
expect(servicePage.find('.service__list-item-name').text()).toBe('Ramon');
});
});