refactor: update test coverage (#202)
* clean up and test segment integration * add tests for action utils * add tests for store aggregator and utils * clean up un-used paths in thunkAction testUtils * clean up filter reducer coverage * add filter reducer tests for filterMenu actions * clean up grades selectors coverage * separate App and add unit tests * ignore external files in coverage analysis * remove old/unused code from StrictDict and clean up tests * clean up FileUploadForm coverage * more cleanup for StrictDict tests * clean up GradesTab test coverage * clean up GradesTab coverage * ignore reducer-mapping for unit-test coverage * clean up AssignmentFilter test coverage * add index-level test coverage * temp remove snapshots * re-add App snapshot * v1.4.41
This commit is contained in:
@@ -1,27 +1,8 @@
|
||||
/* eslint-disable no-console */
|
||||
import util from 'util';
|
||||
|
||||
const staticReturnOptions = [
|
||||
'dict',
|
||||
'inspect',
|
||||
Symbol.toStringTag,
|
||||
util.inspect.custom,
|
||||
Symbol.for('nodejs.util.inspect.custom'),
|
||||
];
|
||||
|
||||
const strictGet = (target, name) => {
|
||||
if (name === Symbol.toStringTag) {
|
||||
return target;
|
||||
}
|
||||
if (name === 'length') {
|
||||
return target.length;
|
||||
}
|
||||
if (staticReturnOptions.indexOf(name) >= 0) {
|
||||
return target;
|
||||
}
|
||||
if (name === Symbol.iterator) {
|
||||
return { ...target };
|
||||
}
|
||||
|
||||
if (name in target || name === '_reactFragment') {
|
||||
return target[name];
|
||||
|
||||
62
src/utils/StrictDict.test.js
Normal file
62
src/utils/StrictDict.test.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import StrictDict from './StrictDict';
|
||||
|
||||
const value1 = 'valUE1';
|
||||
const value2 = 'vALue2';
|
||||
const key1 = 'Key1';
|
||||
const key2 = 'keY2';
|
||||
|
||||
jest.spyOn(window, 'Error').mockImplementation(error => ({ stack: error }));
|
||||
|
||||
describe('StrictDict', () => {
|
||||
let consoleError;
|
||||
let consoleLog;
|
||||
let windowError;
|
||||
beforeEach(() => {
|
||||
consoleError = window.console.error;
|
||||
consoleLog = window.console.lot;
|
||||
windowError = window.Error;
|
||||
window.console.error = jest.fn();
|
||||
window.console.log = jest.fn();
|
||||
window.Error = jest.fn(error => ({ stack: error }));
|
||||
});
|
||||
afterAll(() => {
|
||||
window.console.error = consoleError;
|
||||
window.console.log = consoleLog;
|
||||
window.Error = windowError;
|
||||
});
|
||||
const rawDict = {
|
||||
[key1]: value1,
|
||||
[key2]: value2,
|
||||
};
|
||||
const dict = StrictDict(rawDict);
|
||||
it('provides key access like a normal dict object', () => {
|
||||
expect(dict[key1]).toEqual(value1);
|
||||
});
|
||||
it('allows key listing', () => {
|
||||
expect(Object.keys(dict)).toEqual([key1, key2]);
|
||||
});
|
||||
it('allows item listing', () => {
|
||||
expect(Object.values(dict)).toEqual([value1, value2]);
|
||||
});
|
||||
it('allows stringification', () => {
|
||||
expect(dict.toString()).toEqual(rawDict.toString());
|
||||
expect({ ...dict }).toEqual({ ...rawDict });
|
||||
});
|
||||
it('allows entry listing', () => {
|
||||
expect(Object.entries(dict)).toEqual(Object.entries(rawDict));
|
||||
});
|
||||
describe('missing key', () => {
|
||||
it('logs error with target, name, and error stack', () => {
|
||||
// eslint-ignore-next-line no-unused-vars
|
||||
const callBadKey = () => dict.fakeKey;
|
||||
callBadKey();
|
||||
expect(window.console.error.mock.calls).toEqual([
|
||||
[{ target: dict, name: 'fakeKey' }],
|
||||
[Error('invalid property "fakeKey"').stack],
|
||||
]);
|
||||
});
|
||||
it('returns undefined', () => {
|
||||
expect(dict.fakeKey).toEqual(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user