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
describe('When new item is added in real time', ()=> { | |
it('ENSURE_ACTIVE_ITEMS action is dispatched', async () => { | |
const dispatchSpy = jest.spyOn(store, 'dispatch') | |
wrapper = await renderComponent('top') | |
expect(dispatchSpy).toHaveBeenCalledWith('ENSURE_ACTIVE_ITEMS') | |
}) |
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 { mount } from '@vue/test-utils' | |
import { resolvePromises } from '../../../test/test-utils' | |
import { createStore } from '../../store' | |
import { fakeItem } from '../../../test/fake-data' | |
import ItemView from '../ItemView' | |
let wrapper, store | |
describe('ItemView.vue', () => { |
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
it('Calls the action to fetch the user by id', async () => { | |
const dispatchSpy = jest.spyOn(store, 'dispatch') | |
await renderComponent(route) | |
expect(dispatchSpy).toHaveBeenCalledWith('FETCH_USER', { id: fakeUser.id }) | |
expect(dispatchSpy.mock.calls.length).toBe(1) | |
}) |
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
it('Renders time since creation', async () => { | |
fakeUser.created = new Date('September 07 2018')/1000 | |
Date.now = jest.fn(() => new Date('September 09 2018')) | |
// We extracted a function to avoid repeating the same mount code in all the tests | |
wrapper = await renderComponent(route) | |
expect(wrapper.text()).toContain('2 days ago') | |
}) |
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 { mount } from '@vue/test-utils' | |
import { fakeUser } from '../../../test/fake-data' | |
import { resolvePromises } from '../../../test/test-utils' | |
import { createStore } from '../../store' | |
import UserView from '../UserView' | |
describe('UserView.vue', () => { | |
it('Renders user title', async () => { | |
// Creating a fake route |
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 { mount } from '@vue/test-utils' | |
import { fakeUser } from '../../../test/fake-data' | |
import { createStore } from '../../store' | |
import UserView from '../UserView' | |
describe('UserView.vue', () => { | |
it('Renders user title', () => { | |
// Creating a fake route | |
const route = userRoute(fakeUser.id) |
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 { rejectedPromise, resolvedPromise } from '../../../../../test/helpers' | |
import { retrieveFilmsAction } from '../films-actions' | |
import { queryAction } from '../pattern-actions' | |
describe('REQUEST/SUCCESS/ERROR actions', () => { | |
let action | |
let commitSpy | |
beforeEach(() => { | |
commitSpy = jest.fn() |
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 { retrieveFilms } from '../../repositories/films-repository' | |
import { FETCH_FILMS_ERROR, FETCH_FILMS_REQUEST, FETCH_FILMS_SUCCESS } from './films-mutations' | |
export function retrieveFilmsActionUsingQueryAction() { | |
return queryAction(retrieveFilms, FETCH_FILMS_REQUEST, FETCH_FILMS_SUCCESS, FETCH_FILMS_ERROR).run | |
} | |
export function queryAction(command, REQUEST, SUCCESS, ERROR) { | |
return { run } |
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
// retrieveFilms is function that queries the Studio Ghibli backend and returns a promise with the list of movies | |
// or throws an error if the request failed | |
import { retrieveFilms } from '../../repositories/films-repository' | |
export function buildRetrieveFilmsAction() { | |
return retrieveFilmsAction(retrieveFilms).run | |
} | |
export function retrieveFilmsAction(retrieveFilms) { | |
return { run } |
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
let action | |
let commitSpy | |
beforeEach(() => { | |
commitSpy = jest.fn() | |
}) | |
describe('Retrieving films action', () => { | |
it('finishes with success', async () => { | |
const FILMS = 'ANY FILMS' |
NewerOlder