-
Notifications
You must be signed in to change notification settings - Fork 17
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
Unit tests & fixes #33
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fc05294
add tests for QBreadcrumbs & QButton
cheesytim 11bddd3
add tests for QCascader
cheesytim 02d5acc
fix localization in QDatepicker
cheesytim aa0d78e
add tests to commit hook
cheesytim c61168f
add tests to commit hook
cheesytim 90af52c
change jest config
cheesytim 9807388
fixes
cheesytim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
module.exports = { | ||
moduleFileExtensions: ['js', 'vue', 'json'], | ||
transform: { | ||
'^.+\\.vue$': 'vue-jest', | ||
'^.+\\.js$': 'babel-jest', | ||
'.*\\.(vue)$': 'vue-jest', | ||
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$': | ||
'jest-transform-stub' | ||
}, | ||
collectCoverage: true, | ||
collectCoverageFrom: ['<rootDir>/tests/unit/*.vue'], | ||
setupFiles: ['<rootDir>/tests/unit/setup.js'], | ||
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\](?!lodash-es/).+\\.js$'], | ||
coverageReporters: ['text-summary', 'html', 'lcov', 'clover'] | ||
setupFiles: ['<rootDir>/tests/unit/setup.js'], | ||
testMatch: ['<rootDir>/src/**/*.test.(ts|tsx|js)'], | ||
testURL: 'http://localhost/', | ||
coverageReporters: ['text-summary', 'html', 'lcov', 'clover'], | ||
coverageDirectory: '<rootDir>/tests/unit/coverage', | ||
coverageThreshold: { | ||
global: { | ||
branches: 7, | ||
functions: 14, | ||
lines: 17 | ||
} | ||
} | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Component from './src/QBreadcrumbs'; | ||
|
||
describe('QBreadcrumbs', () => { | ||
let instance; | ||
let options; | ||
|
||
beforeEach(() => { | ||
options = { | ||
mocks: { | ||
$route: { matched: [{ meta: 'one' }] } | ||
} | ||
}; | ||
|
||
instance = shallowMount(Component, options); | ||
}); | ||
|
||
it('should match snapshot', () => { | ||
expect(instance.element).toMatchSnapshot(); | ||
}); | ||
|
||
describe('computed', () => { | ||
it('lastCrumb should return custom last crumb if it has been passed', () => { | ||
const expected = 'one'; | ||
instance.setProps({ | ||
last: expected | ||
}); | ||
|
||
expect(instance.vm.lastCrumb).toEqual(expected); | ||
}); | ||
}); | ||
|
||
describe('pushTo', () => { | ||
it(`should return the router's 'name' if it has been passed`, () => { | ||
const route = { name: 'R_MAIN', path: '/main' }; | ||
const expected = { name: route.name }; | ||
expect(instance.vm.pushTo(route)).toEqual(expected); | ||
}); | ||
|
||
it(`should return the router's 'path' if the 'name' hasn't been passed`, () => { | ||
const route = { path: '/main' }; | ||
const expected = route.path; | ||
expect(instance.vm.pushTo(route)).toEqual(expected); | ||
}); | ||
}); | ||
}); |
16 changes: 16 additions & 0 deletions
16
src/qComponents/QBreadcrumbs/__snapshots__/QBreadcrumbs.test.js.snap
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`QBreadcrumbs should match snapshot 1`] = ` | ||
<div | ||
class="q-breadcrumbs" | ||
> | ||
|
||
<div | ||
class="q-breadcrumbs__crumb q-breadcrumbs__crumb_last" | ||
> | ||
|
||
|
||
|
||
</div> | ||
</div> | ||
`; |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import Component from './src/QButton'; | ||
|
||
describe('QButton', () => { | ||
it('should match snapshot', () => { | ||
const { element } = shallowMount(Component); | ||
expect(element).toMatchSnapshot(); | ||
}); | ||
|
||
it(`should have class 'q-button_type_icon' if type is icon`, () => { | ||
const instance = shallowMount(Component); | ||
const expected = 'q-button_type_icon'; | ||
instance.setProps({ | ||
type: 'icon' | ||
}); | ||
expect(instance.vm.classes).toContain(expected); | ||
}); | ||
|
||
it(`should have class 'q-button_theme_link' if theme is link`, () => { | ||
const instance = shallowMount(Component); | ||
const expected = 'q-button_theme_link'; | ||
instance.setProps({ | ||
theme: 'link' | ||
}); | ||
expect(instance.vm.classes).toContain(expected); | ||
}); | ||
|
||
describe('handleClick', () => { | ||
it('should emit click', () => { | ||
const instance = shallowMount(Component); | ||
instance.vm.handleClick(); | ||
expect(instance.emitted()).toBeTruthy(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. тут кажется стоит указать конкретное событие которое ожидается эмитнутым |
||
}); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
src/qComponents/QButton/__snapshots__/QButton.test.js.snap
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`QButton should match snapshot 1`] = ` | ||
<button | ||
class="q-button q-button_theme_primary q-button_type_default q-button_size_medium" | ||
type="button" | ||
> | ||
<!----> | ||
|
||
<!----> | ||
|
||
<!----> | ||
</button> | ||
`; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import Component from './src/QCascader'; | ||
|
||
describe('QCascader', () => { | ||
let instance; | ||
let options; | ||
|
||
beforeEach(() => { | ||
options = { | ||
mocks: { | ||
$t: () => {} | ||
}, | ||
propsData: { | ||
value: 'resource', | ||
placeholder: 'placeholder', | ||
options: [ | ||
{ | ||
value: 'guide', | ||
label: 'Guide', | ||
children: [ | ||
{ | ||
value: 'child', | ||
label: 'Child', | ||
children: [{ value: 'next child', label: 'Next child' }] | ||
} | ||
] | ||
}, | ||
{ | ||
value: 'resource', | ||
label: 'Resource' | ||
} | ||
] | ||
} | ||
}; | ||
|
||
instance = mount(Component, options); | ||
}); | ||
|
||
it('should match snapshot', () => { | ||
expect(instance.element).toMatchSnapshot(); | ||
}); | ||
|
||
ViZhe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
describe('computed', () => { | ||
describe('model', () => { | ||
it('should set inputValue if has been changed', () => { | ||
const expected = 'guide'; | ||
instance.vm.model = expected; | ||
|
||
expect(instance.vm.inputValue).toEqual(expected); | ||
}); | ||
}); | ||
describe('clearBtnVisible', () => { | ||
it('should return false if showClose is false', () => { | ||
expect(instance.vm.clearBtnVisible).toBeFalsy(); | ||
ViZhe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
it('should return true if showClose is true', () => { | ||
instance.vm.showClose = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. лучше через setData |
||
expect(instance.vm.clearBtnVisible).toBeTruthy(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('watch', () => { | ||
describe('value', () => { | ||
it('should set checkedValues if value is array', async () => { | ||
const expected = ['guide', 'child']; | ||
await instance.setProps({ | ||
value: expected | ||
}); | ||
expect(instance.vm.checkedValues).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
последний тоже должен обрезаться