Change the tests setup to the call of mutations instead of queries.

This commit is contained in:
elweyn 2022-09-22 12:29:03 +02:00
parent 4461ff92a5
commit 98aca9ff52
3 changed files with 11 additions and 10 deletions

View File

@ -18,6 +18,7 @@ const apolloMock = jest.fn().mockResolvedValue({
logout: 'success',
},
})
const apolloQueryMock = jest.fn()
describe('DashboardLayout', () => {
let wrapper
@ -40,7 +41,8 @@ describe('DashboardLayout', () => {
},
},
$apollo: {
query: apolloMock,
mutate: apolloMock,
query: apolloQueryMock,
},
$store: {
state: {
@ -142,7 +144,7 @@ describe('DashboardLayout', () => {
describe('update transactions', () => {
beforeEach(async () => {
apolloMock.mockResolvedValue({
apolloQueryMock.mockResolvedValue({
data: {
transactionList: {
balance: {
@ -163,7 +165,7 @@ describe('DashboardLayout', () => {
})
it('calls the API', () => {
expect(apolloMock).toBeCalledWith(
expect(apolloQueryMock).toBeCalledWith(
expect.objectContaining({
variables: {
currentPage: 2,
@ -201,7 +203,7 @@ describe('DashboardLayout', () => {
describe('update transactions returns error', () => {
beforeEach(async () => {
apolloMock.mockRejectedValue({
apolloQueryMock.mockRejectedValue({
message: 'Ouch!',
})
await wrapper

View File

@ -84,7 +84,6 @@ export default {
this.$router.push('/login')
})
.catch(() => {
console.log('TESTTEST')
this.$store.dispatch('logout')
if (this.$router.currentRoute.path !== '/login') this.$router.push('/login')
})

View File

@ -5,7 +5,7 @@ import Login from './Login'
const localVue = global.localVue
const apolloQueryMock = jest.fn()
const apolloMutateMock = jest.fn()
const mockStoreDispach = jest.fn()
const mockStoreCommit = jest.fn()
const mockRouterPush = jest.fn()
@ -41,7 +41,7 @@ describe('Login', () => {
params: {},
},
$apollo: {
query: apolloQueryMock,
mutate: apolloMutateMock,
},
}
@ -113,7 +113,7 @@ describe('Login', () => {
await wrapper.find('input[placeholder="Email"]').setValue('user@example.org')
await wrapper.find('input[placeholder="form.password"]').setValue('1234')
await flushPromises()
apolloQueryMock.mockResolvedValue({
apolloMutateMock.mockResolvedValue({
data: {
login: 'token',
},
@ -123,7 +123,7 @@ describe('Login', () => {
})
it('calls the API with the given data', () => {
expect(apolloQueryMock).toBeCalledWith(
expect(apolloMutateMock).toBeCalledWith(
expect.objectContaining({
variables: {
email: 'user@example.org',
@ -175,7 +175,7 @@ describe('Login', () => {
describe('login fails', () => {
const createError = async (errorMessage) => {
apolloQueryMock.mockRejectedValue({
apolloMutateMock.mockRejectedValue({
message: errorMessage,
})
wrapper = Wrapper()