UNCLASSIFIED
Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Platform One
P
Party Bus
Launchboard
launchboard-fe
Commits
10a7f324
Commit
10a7f324
authored
Feb 24, 2021
by
graham.smith
Browse files
fix error messages in Training.spec
parent
3d2362b6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
22 deletions
+29
-22
tests/unit/views/super-admin/Training.spec.js
tests/unit/views/super-admin/Training.spec.js
+29
-22
No files found.
tests/unit/views/super-admin/Training.spec.js
View file @
10a7f324
...
@@ -3,10 +3,9 @@ import Training from "@/views/super-admin/Training.vue";
...
@@ -3,10 +3,9 @@ import Training from "@/views/super-admin/Training.vue";
import
TrainingService
from
"
@/api/services/training
"
;
import
TrainingService
from
"
@/api/services/training
"
;
describe
(
"
Training
"
,
()
=>
{
describe
(
"
Training
"
,
()
=>
{
const
mockCoursesResult
=
{
courses
:
[],
meta
:
{
total
:
0
}
};
it
(
"
should debounce getCourses
"
,
async
()
=>
{
it
(
"
should debounce getCourses
"
,
async
()
=>
{
TrainingService
.
getCourses
=
jest
TrainingService
.
getCourses
=
jest
.
fn
().
mockResolvedValue
(
mockCoursesResult
);
.
fn
()
.
mockResolvedValue
({
items
:
[],
total
:
0
});
const
wrapper
=
shallowMount
(
Training
);
const
wrapper
=
shallowMount
(
Training
);
wrapper
.
vm
.
fetchDebounced
();
wrapper
.
vm
.
fetchDebounced
();
...
@@ -31,6 +30,7 @@ describe("Training", () => {
...
@@ -31,6 +30,7 @@ describe("Training", () => {
});
});
it
(
"
should handle error on getCourses
"
,
async
()
=>
{
it
(
"
should handle error on getCourses
"
,
async
()
=>
{
console
.
error
=
jest
.
fn
();
// mock console.error when expecting error messages
TrainingService
.
getCourses
=
jest
.
fn
().
mockRejectedValue
(
"
mock error
"
);
TrainingService
.
getCourses
=
jest
.
fn
().
mockRejectedValue
(
"
mock error
"
);
const
wrapper
=
shallowMount
(
Training
);
const
wrapper
=
shallowMount
(
Training
);
...
@@ -65,26 +65,33 @@ describe("Training", () => {
...
@@ -65,26 +65,33 @@ describe("Training", () => {
// });
// });
//
//
it
(
"
should remove selected courses
"
,
async
()
=>
{
describe
(
"
remove courses
"
,
()
=>
{
TrainingService
.
deleteCourses
=
jest
.
fn
().
mockResolvedValue
();
it
(
"
should remove selected courses
"
,
async
()
=>
{
TrainingService
.
deleteCourses
=
jest
.
fn
().
mockResolvedValue
();
const
wrapper
=
shallowMount
(
Training
);
const
wrapper
=
shallowMount
(
Training
);
const
mockCourses
=
[{
name
:
"
mock course1
"
},
{
name
:
"
mock course2
"
}];
const
mockCourses
=
[{
name
:
"
mock course1
"
},
{
name
:
"
mock course2
"
}];
wrapper
.
vm
.
selectedCourses
=
mockCourses
;
wrapper
.
vm
.
selectedCourses
=
mockCourses
;
await
wrapper
.
vm
.
removeSelected
();
await
wrapper
.
vm
.
removeSelected
();
expect
(
TrainingService
.
deleteCourses
).
toHaveBeenCalledTimes
(
1
);
expect
(
TrainingService
.
deleteCourses
).
toHaveBeenCalledTimes
(
1
);
expect
(
TrainingService
.
deleteCourses
).
toHaveBeenCalledWith
(
mockCourses
);
expect
(
TrainingService
.
deleteCourses
).
toHaveBeenCalledWith
(
mockCourses
);
expect
(
wrapper
.
vm
.
snackbars
.
delete
).
toEqual
(
true
);
expect
(
wrapper
.
vm
.
snackbars
.
delete
).
toEqual
(
true
);
expect
(
wrapper
.
vm
.
state
.
isDeleting
).
toEqual
(
false
);
expect
(
wrapper
.
vm
.
state
.
isDeleting
).
toEqual
(
false
);
expect
(
wrapper
.
vm
.
selectedCourses
).
toHaveLength
(
0
);
expect
(
wrapper
.
vm
.
selectedCourses
).
toHaveLength
(
0
);
});
// error state
it
(
"
should remove selected courses
"
,
async
()
=>
{
TrainingService
.
deleteCourses
=
jest
.
fn
().
mockRejectedValue
(
"
mock error
"
);
console
.
error
=
jest
.
fn
();
// mock console.error when expecting error messages
await
wrapper
.
vm
.
removeSelected
();
TrainingService
.
deleteCourses
=
jest
.
fn
().
mockResolvedValue
();
expect
(
wrapper
.
vm
.
snackbars
.
delete
).
toEqual
(
false
);
expect
(
wrapper
.
vm
.
state
.
isDeleting
).
toEqual
(
false
);
const
wrapper
=
shallowMount
(
Training
);
expect
(
wrapper
.
vm
.
selectedCourses
).
toHaveLength
(
0
);
TrainingService
.
deleteCourses
=
jest
.
fn
().
mockRejectedValue
(
"
mock error
"
);
await
wrapper
.
vm
.
removeSelected
();
expect
(
wrapper
.
vm
.
snackbars
.
delete
).
toEqual
(
false
);
expect
(
wrapper
.
vm
.
state
.
isDeleting
).
toEqual
(
false
);
expect
(
wrapper
.
vm
.
selectedCourses
).
toHaveLength
(
0
);
});
});
});
it
(
"
should compute css class for courses
"
,
async
()
=>
{
it
(
"
should compute css class for courses
"
,
async
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment