Skip to content

Commit ef628ae

Browse files
committed
Updated error handling tests
1 parent 5f3e5b9 commit ef628ae

File tree

1 file changed

+64
-9
lines changed

1 file changed

+64
-9
lines changed

tests/lib.test.js

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test, describe, assert } from "vitest";
1+
import { expect, test, describe, vi, afterAll, beforeEach } from "vitest";
22
import {
33
abbreviate,
44
adaptColorToBackground,
@@ -806,55 +806,110 @@ describe('objectIsEmpty', () => {
806806
})
807807

808808
describe('error', () => {
809+
const consoleMock = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
810+
811+
afterAll(() => {
812+
consoleMock.mockReset()
813+
})
814+
815+
beforeEach(() => {
816+
consoleMock.mockReset()
817+
})
818+
809819
test('throws an error for missing dataset', () => {
810820
try {
811821
error({
812822
componentName: 'VueUiXy',
813-
type: 'dataset'
823+
type: 'dataset',
824+
warn: false
814825
});
815826
fail('Error was not thrown');
816827
} catch (error) {
817-
expect(error.message).toBe('\n\n> VueUiXy is missing the dataset prop.\n');
828+
expect(error.message).toBe('\n> VueUiXy is missing the dataset prop.\n');
818829
}
819830
});
820831

832+
test('logs a warning for missing dataset', () => {
833+
error({
834+
componentName: 'VueUiXy',
835+
type: 'dataset',
836+
});
837+
expect(consoleMock).toHaveBeenCalledOnce();
838+
expect(consoleMock).toHaveBeenLastCalledWith('\n> VueUiXy is missing the dataset prop.\n');
839+
});
840+
821841
test('throws an error for missing dataset object required attribute', () => {
822842
try {
823843
error({
824844
componentName: 'VueUiXy',
825845
type: 'datasetAttribute',
826-
property: 'name'
846+
property: 'name',
847+
warn: false
827848
});
828849
fail('Error was not thrown');
829850
} catch (error) {
830-
expect(error.message).toBe('\n\n> VueUiXy dataset is missing the name attribute.\n')
851+
expect(error.message).toBe('\n> VueUiXy dataset is missing the name attribute.\n')
831852
}
832853
})
833854

855+
test('logs a warning for missing dataset object required attribute', () => {
856+
error({
857+
componentName: 'VueUiXy',
858+
type: 'datasetAttribute',
859+
property: 'name',
860+
});
861+
expect(consoleMock).toHaveBeenCalledOnce();
862+
expect(consoleMock).toHaveBeenLastCalledWith('\n> VueUiXy dataset is missing the name attribute.\n');
863+
})
864+
865+
834866
test('throws an error for missing datasetItem required attribute', () => {
835867
try {
836868
error({
837869
componentName: 'VueUiXy',
838870
type: 'datasetSerieAttribute',
839871
property: 'name',
840-
index: 0
872+
index: 0,
873+
warn: false
841874
});
842875
fail('Error was not thrown');
843876
} catch (error) {
844-
expect(error.message).toBe('\n\n> VueUiXy dataset item at index 0 is missing the name attribute.\n')
877+
expect(error.message).toBe('\n> VueUiXy dataset item at index 0 is missing the name attribute.\n')
845878
}
846879
})
847880

881+
test('logs a warning for missing datasetItem required attribute', () => {
882+
error({
883+
componentName: 'VueUiXy',
884+
type: 'datasetSerieAttribute',
885+
property: 'name',
886+
index: 0,
887+
});
888+
expect(consoleMock).toHaveBeenCalledOnce();
889+
expect(consoleMock).toHaveBeenLastCalledWith('\n> VueUiXy dataset item at index 0 is missing the name attribute.\n');
890+
})
891+
848892
test('throws an error for an empty dataset array item', () => {
849893
try {
850894
error({
851895
componentName: 'VueUiXy',
852896
type: 'datasetAttributeEmpty',
853-
property: 'series'
897+
property: 'series',
898+
warn: false
854899
});
855900
fail('Error was not thrown');
856901
} catch (error) {
857-
expect(error.message).toBe('\n\n> VueUiXy dataset series attribute cannot be empty.\n')
902+
expect(error.message).toBe('\n> VueUiXy dataset series attribute cannot be empty.\n')
858903
}
859904
})
905+
906+
test('logs a warning for an empty dataset array item', () => {
907+
error({
908+
componentName: 'VueUiXy',
909+
type: 'datasetAttributeEmpty',
910+
property: 'series',
911+
});
912+
expect(consoleMock).toHaveBeenCalledOnce();
913+
expect(consoleMock).toHaveBeenLastCalledWith('\n> VueUiXy dataset series attribute cannot be empty.\n');
914+
})
860915
});

0 commit comments

Comments
 (0)