Skip to content

Move to kcd-scripts #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Aug 18, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Cleanup custom store test
  • Loading branch information
afontcu committed Aug 17, 2019
commit fa85fa5fd85e7787050801dd75032a48da0554c1
26 changes: 14 additions & 12 deletions src/__tests__/vuex.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import '@testing-library/jest-dom/extend-expect'
import { cleanup, render, fireEvent } from '@testing-library/vue'
import {cleanup, render, fireEvent} from '@testing-library/vue'

import VuexTest from './components/Store/VuexTest'
import { store } from './components/Store/store'
import {store} from './components/Store/store'

afterEach(cleanup)

Expand All @@ -16,41 +16,43 @@ function renderVuexTestComponent(customStore) {
// Render the component and merge the original store and the custom one
// provided as a parameter. This way, we can alter some behaviors of the
// initial implementation.
return render(VuexTest, { store: { ...store, ...customStore } })
return render(VuexTest, {store: {...store, ...customStore}})
}

test('can render with vuex with defaults', async () => {
const { getByTestId, getByText } = renderVuexTestComponent()
const {getByTestId, getByText} = renderVuexTestComponent()
await fireEvent.click(getByText('+'))

expect(getByTestId('count-value')).toHaveTextContent('1')
})

test('can render with vuex with custom initial state', async () => {
const { getByTestId, getByText } = renderVuexTestComponent({
state: { count: 3 }
const {getByTestId, getByText} = renderVuexTestComponent({
state: {count: 3},
})
await fireEvent.click(getByText('-'))

expect(getByTestId('count-value')).toHaveTextContent('2')
})

test('can render with vuex with custom store', async () => {
jest.spyOn(console, 'error').mockImplementation(() => {})

// This is a silly store that can never be changed.
// eslint-disable-next-line no-shadow
const store = { state: { count: 1000 } }
const store = {
state: {count: 1000},
actions: {
increment: () => jest.fn(),
decrement: () => jest.fn(),
},
}

// Notice how here we are not using the helper method, because there's no
// need to do that.
const { getByTestId, getByText } = render(VuexTest, { store })
const {getByTestId, getByText} = render(VuexTest, {store})

await fireEvent.click(getByText('+'))
expect(getByTestId('count-value')).toHaveTextContent('1000')

await fireEvent.click(getByText('-'))
expect(getByTestId('count-value')).toHaveTextContent('1000')

expect(console.error).toHaveBeenCalledTimes(1)
})