Ensure tests do not log warning or errors
This commit increases strictnes of tests by failing on tests (even though they pass) if `console.warn` or `console.error` is used. This is used to fix warning outputs from Vue, cleaning up test output and preventing potential issues with tests. This commit fixes all of the failing tests, including refactoring in code to make them more testable through injecting Vue lifecycle hook function stubs. This removes `shallowMount`ing done on places, improving the speed of executing unit tests. It also reduces complexity and increases maintainability by removing `@vue/test-utils` dependency for these tests. Changes: - Register global hook for all tests to fail if console.error or console.warn is being used. - Fix all issues with failing tests. - Create test helper function for running code in a wrapper component to run code in reliable/unified way to surpress Vue warnings about code not running inside `setup`.
This commit is contained in:
@@ -13,23 +13,10 @@ describe('CircleRating.vue', () => {
|
||||
const currentRating = MAX_RATING - 1;
|
||||
|
||||
// act
|
||||
const wrapper = shallowMount(CircleRating, {
|
||||
propsData: {
|
||||
rating: currentRating,
|
||||
},
|
||||
const wrapper = mountComponent({
|
||||
rating: currentRating,
|
||||
});
|
||||
|
||||
// assert
|
||||
const ratingCircles = wrapper.findAllComponents(RatingCircle);
|
||||
expect(ratingCircles.length).to.equal(expectedMaxRating);
|
||||
});
|
||||
it('renders the correct number of RatingCircle components for default rating', () => {
|
||||
// arrange
|
||||
const expectedMaxRating = MAX_RATING;
|
||||
|
||||
// act
|
||||
const wrapper = shallowMount(CircleRating);
|
||||
|
||||
// assert
|
||||
const ratingCircles = wrapper.findAllComponents(RatingCircle);
|
||||
expect(ratingCircles.length).to.equal(expectedMaxRating);
|
||||
@@ -42,10 +29,8 @@ describe('CircleRating.vue', () => {
|
||||
const expectedTotalComponents = 3;
|
||||
|
||||
// act
|
||||
const wrapper = shallowMount(CircleRating, {
|
||||
propsData: {
|
||||
rating: expectedTotalComponents,
|
||||
},
|
||||
const wrapper = mountComponent({
|
||||
rating: expectedTotalComponents,
|
||||
});
|
||||
|
||||
// assert
|
||||
@@ -87,3 +72,13 @@ describe('CircleRating.vue', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function mountComponent(options: {
|
||||
readonly rating: number,
|
||||
}) {
|
||||
return shallowMount(CircleRating, {
|
||||
props: {
|
||||
rating: options.rating,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user