Skip to content

Commit b7498a2

Browse files
author
Jérémy
committed
test(mixin): adds tests that check presence of created hook and fix test for dynamic service
1 parent fd2f97c commit b7498a2

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

test/make-find-mixin.test.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ eslint
33
@typescript-eslint/explicit-function-return-type: 0,
44
@typescript-eslint/no-explicit-any: 0
55
*/
6-
import jsdom from 'jsdom-global'
76
import { assert } from 'chai'
8-
import feathersVuex, { FeathersVuex } from '../src/index'
9-
import { feathersRestClient as feathersClient } from './fixtures/feathers-client'
10-
import makeFindMixin from '../src/make-find-mixin'
7+
import jsdom from 'jsdom-global'
118
import Vue from 'vue/dist/vue'
129
import Vuex from 'vuex'
10+
import feathersVuex, { FeathersVuex } from '../src/index'
11+
import makeFindMixin from '../src/make-find-mixin'
12+
import { feathersRestClient as feathersClient } from './fixtures/feathers-client'
1313

1414
jsdom()
1515
require('events').EventEmitter.prototype._maxListeners = 100
@@ -44,7 +44,7 @@ describe('Find Mixin', function() {
4444

4545
it('correctly forms mixin data', function() {
4646
const todosMixin = makeFindMixin({ service: 'todos' })
47-
47+
// todosMixin.
4848
interface TodosComponent {
4949
todos: []
5050
todosServiceName: string
@@ -80,6 +80,10 @@ describe('Find Mixin', function() {
8080
assert(vm.haveTodosLoadedOnce === false, 'loaded once boolean is in place')
8181
assert(typeof vm.findTodos === 'function', 'the find action is in place')
8282
assert(vm.todosLocal === false, 'local boolean is false by default')
83+
assert(
84+
typeof vm.$options.created[0] === 'function',
85+
'created lifecycle hook function is in place given that local is false'
86+
)
8387
assert(
8488
vm.todosQid === 'default',
8589
'the default query identifier is in place'
@@ -96,11 +100,12 @@ describe('Find Mixin', function() {
96100
)
97101
})
98102

99-
it.skip('correctly forms mixin data for dynamic service', function() {
103+
it('correctly forms mixin data for dynamic service', function() {
100104
const tasksMixin = makeFindMixin({
101105
service() {
102106
return this.serviceName
103-
}
107+
},
108+
local: true
104109
})
105110

106111
interface TasksComponent {
@@ -116,7 +121,7 @@ describe('Find Mixin', function() {
116121
}
117122

118123
const vm = new Vue({
119-
name: 'tasls-component',
124+
name: 'tasks-component',
120125
data: () => ({
121126
serviceName: 'tasks'
122127
}),
@@ -125,27 +130,31 @@ describe('Find Mixin', function() {
125130
template: `<div></div>`
126131
}).$mount()
127132

128-
assert.deepEqual(vm.tasks, [], 'tasks prop was empty array')
133+
assert.deepEqual(vm.items, [], 'items prop was empty array')
129134
assert(
130-
vm.hasOwnProperty('tasksPaginationData'),
135+
vm.hasOwnProperty('servicePaginationData'),
131136
'pagination data prop was present, even if undefined'
132137
)
133-
assert(vm.tasksServiceName === 'tasks', 'service name was correct')
134-
assert(vm.isFindTasksPending === false, 'loading boolean is in place')
135-
assert(typeof vm.findTasks === 'function', 'the find action is in place')
136-
assert(vm.tasksLocal === false, 'local boolean is false by default')
138+
assert(vm.serviceServiceName === 'tasks', 'service name was correct')
139+
assert(vm.isFindServicePending === false, 'loading boolean is in place')
140+
assert(typeof vm.findService === 'function', 'the find action is in place')
141+
assert(vm.serviceLocal === true, 'local boolean is set to true')
142+
assert(
143+
typeof vm.$options.created === 'undefined',
144+
'created lifecycle hook function is NOT in place given that local is true'
145+
)
137146
assert(
138-
vm.tasksQid === 'default',
147+
vm.serviceQid === 'default',
139148
'the default query identifier is in place'
140149
)
141-
assert(vm.tasksQueryWhen() === true, 'the default queryWhen is true')
150+
assert(vm.serviceQueryWhen === true, 'the default queryWhen is true')
142151
// assert(vm.tasksWatch.length === 0, 'the default watch is an empty array')
143152
assert(
144-
vm.tasksParams === undefined,
153+
vm.serviceParams === undefined,
145154
'no params are in place by default, must be specified by the user'
146155
)
147156
assert(
148-
vm.tasksFetchParams === undefined,
157+
vm.serviceFetchParams === undefined,
149158
'no fetch params are in place by default, must be specified by the user'
150159
)
151160
})

0 commit comments

Comments
 (0)