Skip to content

Instantly share code, notes, and snippets.

View bmdalex's full-sized avatar
🏠
Working from home

Alex B bmdalex

🏠
Working from home
View GitHub Profile
@bmdalex
bmdalex / RegistrationForm.spec.ts
Created January 24, 2021 21:29
DON'T create tests with many assertions (ideally just one assertion / test)
test('when the user submits a valid form should register the user', () => {
/*
* preconditions
*/
expect(getFormSubmitButton(wrapper).attributes('disabled')).toBe(undefined)
expect($auth.registerUser).toHaveBeenCalledWith({ email: validEmail })
expect(wrapper.emitted()['register-update'][0]).toBe(registerUserResponse)
})
@bmdalex
bmdalex / RegistrationForm.spec.ts
Created January 24, 2021 21:31
DO split tests using the frameworks' capabilities
describe('when the user submits a valid form', () => {
beforeEach(() => {
  /*
  * preconditions
  */
  })
it('should enable the submit button', () => {
expect(getFormSubmitButton(wrapper).attributes('disabled')).toBe(undefined)
  })
@bmdalex
bmdalex / RegistrationForm.spec.ts
Created January 24, 2021 21:34
DON'T use names of internal properties
describe('handleFormSubmit', () => {
 beforeEach(() => { … })
it('button disabled attribute is false', { ... })
  it('is calling $auth.registerUser', () => { ... })
  it('is calling $emit("register-update", ...)', { ... })
})
@bmdalex
bmdalex / RegistrationForm.spec.ts
Created January 24, 2021 21:37
DO use sentences that describe the behaviour of the component
describe('when the user submits a valid form', () => {
beforeEach(() => { ... })
it('should enable the submit button', { ... })
 it('should register the user by calling external API', () => { ... })
  it('should emit the "register-update" event', { ... })
})
@bmdalex
bmdalex / RegistrationForm.spec.ts
Created January 24, 2021 21:57
RegistrationForm.spec.ts full test fine
import { createLocalVue, shallowMount } from '@vue/test-utils'
import { createBuilder, testData } from './RegistrationFormComponent.builder.js'
import RegistrationForm from './RegistrationForm.vue'
import { byTestId } from '@/utils/testUtils.js'
const localVue = createLocalVue()
const validEmail = 'somename@example.com'
const invalidEmail = 'invalid email'
const registerUserResponse = { status: 200 }

Healthy Foods Inventory Challenge

Description

We are the owners of a vegan-friendly store and would like you to create a visual representation of our inventory.

There are two main task described in the sections below.

Feature 1: Display products in a rich text table