Skip to content

Commit 2a9f69f

Browse files
committed
(test) setup jest
1 parent b03bfc8 commit 2a9f69f

File tree

6 files changed

+123
-1
lines changed

6 files changed

+123
-1
lines changed

.babelrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": [["@babel/preset-env", { "modules": false }]],
3+
"env": {
4+
"test": {
5+
"presets": [["@babel/preset-env", { "targets": { "node": "current" } }]]
6+
}
7+
}
8+
}

jest.config.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
verbose: true,
3+
moduleFileExtensions: ['js', 'json', 'vue'],
4+
transform: {
5+
'.*\\.(vue)$': 'vue-jest',
6+
'^.+\\.js$': '<rootDir>/node_modules/babel-jest'
7+
}
8+
// collectCoverage: true,
9+
// collectCoverageFrom: ['src/components/*.{js,vue}', '!**/node_modules/**'],
10+
// coverageReporters: ['html', 'text-summary']
11+
}

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"build:wc": "vue-cli-service build --target wc --no-clean --name vue-advanced-chat ./src/ChatWindow/ChatWindow.vue",
3737
"prepublish": "npm run lint && npm run build",
3838
"publish-beta": "npm publish --tag beta",
39-
"lint": "vue-cli-service lint"
39+
"lint": "vue-cli-service lint",
40+
"test": "jest"
4041
},
4142
"typings": "types/index.d.ts",
4243
"files": [
@@ -55,14 +56,18 @@
5556
"@vue/cli-service": "~4.5.0",
5657
"@vue/eslint-config-standard": "^4.0.0",
5758
"@vue/eslint-config-typescript": "^5.0.2",
59+
"@vue/test-utils": "^1.1.3",
5860
"babel-eslint": "^10.0.3",
61+
"babel-jest": "^23.6.0",
5962
"eslint": "^6.7.2",
6063
"eslint-plugin-vue": "^7.5.0",
64+
"jest": "^23.6.0",
6165
"node-sass": "^4.13.0",
6266
"rimraf": "^2.7.1",
6367
"sass-loader": "^8.0.2",
6468
"typescript": "^4.0.5",
6569
"vue": "^2.6.10",
70+
"vue-jest": "^3.0.7",
6671
"vue-template-compiler": "^2.6.11"
6772
},
6873
"dependencies": {

tests/unit/.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
env: {
3+
jest: true
4+
}
5+
}

tests/unit/RoomsList.spec.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { shallowMount } from '@vue/test-utils'
2+
import RoomsList from '../../src/ChatWindow/RoomsList/RoomsList'
3+
4+
import mockData from './mock-data'
5+
6+
let wrapper
7+
8+
beforeEach(() => {
9+
wrapper = shallowMount(RoomsList, {
10+
propsData: {
11+
currentUserId: mockData.currentUserId,
12+
textMessages: mockData.textMessages,
13+
showRoomsList: true,
14+
showAddRoom: mockData.showAddRoom,
15+
textFormatting: mockData.textFormatting,
16+
isMobile: false,
17+
rooms: mockData.rooms,
18+
loadingRooms: mockData.loadingRooms,
19+
roomsLoaded: mockData.roomsLoaded,
20+
room: mockData.rooms[0],
21+
roomActions: mockData.roomActions
22+
}
23+
})
24+
})
25+
26+
afterEach(() => {
27+
wrapper.destroy()
28+
})
29+
30+
describe('RoomsList', () => {
31+
test('is a Vue instance', () => {
32+
expect(wrapper.isVueInstance).toBeTruthy()
33+
})
34+
})

tests/unit/mock-data.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const height = '100px'
2+
const currentUserId = 'user_1'
3+
const rooms = [{ _id: 1 }]
4+
const loadingRooms = false
5+
const roomsLoaded = true
6+
const roomId = 'room_1'
7+
const loadFirstRoom = true
8+
const messages = [{ _id: 1 }]
9+
const roomMessage = ''
10+
const messagesLoaded = true
11+
const roomActions = [{ title: 'A room action' }]
12+
const menuActions = [{ title: 'A menu action' }]
13+
const messageActions = [{ title: 'A message action' }]
14+
const showAddRoom = true
15+
const showSendIcon = true
16+
const showFiles = true
17+
const showAudio = true
18+
const showEmojis = true
19+
const showReactionEmojis = true
20+
const showNewMessagesDivider = true
21+
const showFooter = true
22+
const textMessages = { ROOMS_EMPTY: 'No rooms' }
23+
const textFormatting = true
24+
const responsiveBreakpoint = 10
25+
const singleRoom = false
26+
const theme = 'dark'
27+
const acceptedFiles = '*'
28+
const styles = { general: { color: '#0a0a0a' } }
29+
30+
export default {
31+
height,
32+
currentUserId,
33+
rooms,
34+
loadingRooms,
35+
roomsLoaded,
36+
roomId,
37+
loadFirstRoom,
38+
messages,
39+
roomMessage,
40+
messagesLoaded,
41+
roomActions,
42+
menuActions,
43+
messageActions,
44+
showAddRoom,
45+
showSendIcon,
46+
showFiles,
47+
showAudio,
48+
showEmojis,
49+
showReactionEmojis,
50+
showNewMessagesDivider,
51+
showFooter,
52+
textMessages,
53+
textFormatting,
54+
responsiveBreakpoint,
55+
singleRoom,
56+
theme,
57+
acceptedFiles,
58+
styles
59+
}

0 commit comments

Comments
 (0)