chore: migrate redux tests to reducer folder and add eslint jest plugin
This commit is contained in:
parent
ef0d2bf195
commit
d12b28b5f5
|
@ -17,14 +17,15 @@ module.exports = {
|
|||
legacyDecorators: true
|
||||
}
|
||||
},
|
||||
plugins: ['react', 'jsx-a11y', 'import', 'react-native', '@babel'],
|
||||
plugins: ['react', 'jsx-a11y', 'import', 'react-native', '@babel', 'jest'],
|
||||
env: {
|
||||
browser: true,
|
||||
commonjs: true,
|
||||
es6: true,
|
||||
node: true,
|
||||
jquery: true,
|
||||
mocha: true
|
||||
mocha: true,
|
||||
'jest/globals': true
|
||||
},
|
||||
rules: {
|
||||
'import/extensions': [
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { setActiveUsers } from '../../app/actions/activeUsers';
|
||||
import { IActiveUsers } from '../../app/reducers/activeUsers';
|
||||
import { mockedStore } from '../../__mocks__/mockedStore';
|
||||
import { setActiveUsers } from '../actions/activeUsers';
|
||||
import { IActiveUsers } from './activeUsers';
|
||||
import { mockedStore } from './mockedStore';
|
||||
|
||||
describe('test reducer', () => {
|
||||
it('should return {} as initial state', async () => {
|
||||
it('should return {} as initial state', () => {
|
||||
const state = mockedStore.getState().activeUsers;
|
||||
expect(state).toEqual({});
|
||||
});
|
||||
it('should return modified store after action', async () => {
|
||||
it('should return modified store after action', () => {
|
||||
const activeUsers: IActiveUsers = { any: { status: 'online', statusText: 'any' } };
|
||||
mockedStore.dispatch(setActiveUsers(activeUsers));
|
||||
const state = mockedStore.getState().activeUsers;
|
|
@ -1,7 +1,7 @@
|
|||
import { applyMiddleware, compose, createStore } from 'redux';
|
||||
import createSagaMiddleware from 'redux-saga';
|
||||
|
||||
import reducers from '../app/reducers';
|
||||
import reducers from '.';
|
||||
|
||||
const enhancers = compose(applyMiddleware(createSagaMiddleware()));
|
||||
export const mockedStore = createStore(reducers, enhancers);
|
|
@ -1,5 +1,5 @@
|
|||
import { addUser, reset, setLoading, removeUser } from '../../app/actions/selectedUsers';
|
||||
import { mockedStore } from '../../__mocks__/mockedStore';
|
||||
import { addUser, reset, setLoading, removeUser } from '../actions/selectedUsers';
|
||||
import { mockedStore } from './mockedStore';
|
||||
|
||||
describe('test selectedUsers reducer', () => {
|
||||
const initialState = {
|
||||
|
@ -7,32 +7,32 @@ describe('test selectedUsers reducer', () => {
|
|||
loading: false
|
||||
};
|
||||
|
||||
it('should return initial state', async () => {
|
||||
it('should return initial state', () => {
|
||||
const state = mockedStore.getState().selectedUsers;
|
||||
expect(state).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('should return modified store after addUser', async () => {
|
||||
it('should return modified store after addUser', () => {
|
||||
const user = { _id: 'xxx', name: 'xxx', fname: 'xxx' };
|
||||
mockedStore.dispatch(addUser(user));
|
||||
const state = mockedStore.getState().selectedUsers.users;
|
||||
expect(state).toEqual([user]);
|
||||
});
|
||||
|
||||
it('should return empty store after remove user', async () => {
|
||||
it('should return empty store after remove user', () => {
|
||||
const user = { _id: 'xxx', name: 'xxx', fname: 'xxx' };
|
||||
mockedStore.dispatch(removeUser(user));
|
||||
const state = mockedStore.getState().selectedUsers.users;
|
||||
expect(state).toEqual([]);
|
||||
});
|
||||
|
||||
it('should return initialState after reset', async () => {
|
||||
it('should return initialState after reset', () => {
|
||||
mockedStore.dispatch(reset());
|
||||
const state = mockedStore.getState().selectedUsers;
|
||||
expect(state).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('should return loading after call action', async () => {
|
||||
it('should return loading after call action', () => {
|
||||
mockedStore.dispatch(setLoading(true));
|
||||
const state = mockedStore.getState().selectedUsers.loading;
|
||||
expect(state).toEqual(true);
|
|
@ -164,6 +164,7 @@
|
|||
"eslint": "^7.31.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-import": "2.22.0",
|
||||
"eslint-plugin-jest": "^25.3.0",
|
||||
"eslint-plugin-jsx-a11y": "6.3.1",
|
||||
"eslint-plugin-react": "7.20.3",
|
||||
"eslint-plugin-react-native": "3.8.1",
|
||||
|
|
76
yarn.lock
76
yarn.lock
|
@ -4314,7 +4314,7 @@
|
|||
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.7.tgz#98a993516c859eb0d5c4c8f098317a9ea68db9ad"
|
||||
integrity sha512-cxWFQVseBm6O9Gbw1IWb8r6OS4OhSt3hPZLkFApLjM8TEXROBuQGLAH2i2gZpcXdLBIrpXuTDhH7Vbm1iXmNGA==
|
||||
|
||||
"@types/json-schema@^7.0.7":
|
||||
"@types/json-schema@^7.0.7", "@types/json-schema@^7.0.9":
|
||||
version "7.0.9"
|
||||
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d"
|
||||
integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==
|
||||
|
@ -4593,6 +4593,18 @@
|
|||
eslint-scope "^5.1.1"
|
||||
eslint-utils "^3.0.0"
|
||||
|
||||
"@typescript-eslint/experimental-utils@^5.0.0":
|
||||
version "5.8.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/experimental-utils/-/experimental-utils-5.8.0.tgz#0916ffe98d34b3c95e3652efa0cace61a7b25728"
|
||||
integrity sha512-KN5FvNH71bhZ8fKtL+lhW7bjm7cxs1nt+hrDZWIqb6ViCffQcWyLunGrgvISgkRojIDcXIsH+xlFfI4RCDA0xA==
|
||||
dependencies:
|
||||
"@types/json-schema" "^7.0.9"
|
||||
"@typescript-eslint/scope-manager" "5.8.0"
|
||||
"@typescript-eslint/types" "5.8.0"
|
||||
"@typescript-eslint/typescript-estree" "5.8.0"
|
||||
eslint-scope "^5.1.1"
|
||||
eslint-utils "^3.0.0"
|
||||
|
||||
"@typescript-eslint/parser@^4.28.5":
|
||||
version "4.31.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-4.31.0.tgz#87b7cd16b24b9170c77595d8b1363f8047121e05"
|
||||
|
@ -4611,11 +4623,24 @@
|
|||
"@typescript-eslint/types" "4.31.0"
|
||||
"@typescript-eslint/visitor-keys" "4.31.0"
|
||||
|
||||
"@typescript-eslint/scope-manager@5.8.0":
|
||||
version "5.8.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.8.0.tgz#2371095b4fa4c7be6a80b380f4e1b49c715e16f4"
|
||||
integrity sha512-x82CYJsLOjPCDuFFEbS6e7K1QEWj7u5Wk1alw8A+gnJiYwNnDJk0ib6PCegbaPMjrfBvFKa7SxE3EOnnIQz2Gg==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "5.8.0"
|
||||
"@typescript-eslint/visitor-keys" "5.8.0"
|
||||
|
||||
"@typescript-eslint/types@4.31.0":
|
||||
version "4.31.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.31.0.tgz#9a7c86fcc1620189567dc4e46cad7efa07ee8dce"
|
||||
integrity sha512-9XR5q9mk7DCXgXLS7REIVs+BaAswfdHhx91XqlJklmqWpTALGjygWVIb/UnLh4NWhfwhR5wNe1yTyCInxVhLqQ==
|
||||
|
||||
"@typescript-eslint/types@5.8.0":
|
||||
version "5.8.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.8.0.tgz#e7fa74ec35d9dbe3560d039d3d8734986c3971e0"
|
||||
integrity sha512-LdCYOqeqZWqCMOmwFnum6YfW9F3nKuxJiR84CdIRN5nfHJ7gyvGpXWqL/AaW0k3Po0+wm93ARAsOdzlZDPCcXg==
|
||||
|
||||
"@typescript-eslint/typescript-estree@4.31.0":
|
||||
version "4.31.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.31.0.tgz#4da4cb6274a7ef3b21d53f9e7147cc76f278a078"
|
||||
|
@ -4629,6 +4654,19 @@
|
|||
semver "^7.3.5"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/typescript-estree@5.8.0":
|
||||
version "5.8.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.8.0.tgz#900469ba9d5a37f4482b014ecce4a5dbb86cb4dd"
|
||||
integrity sha512-srfeZ3URdEcUsSLbkOFqS7WoxOqn8JNil2NSLO9O+I2/Uyc85+UlfpEvQHIpj5dVts7KKOZnftoJD/Fdv0L7nQ==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "5.8.0"
|
||||
"@typescript-eslint/visitor-keys" "5.8.0"
|
||||
debug "^4.3.2"
|
||||
globby "^11.0.4"
|
||||
is-glob "^4.0.3"
|
||||
semver "^7.3.5"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/visitor-keys@4.31.0":
|
||||
version "4.31.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.31.0.tgz#4e87b7761cb4e0e627dc2047021aa693fc76ea2b"
|
||||
|
@ -4637,6 +4675,14 @@
|
|||
"@typescript-eslint/types" "4.31.0"
|
||||
eslint-visitor-keys "^2.0.0"
|
||||
|
||||
"@typescript-eslint/visitor-keys@5.8.0":
|
||||
version "5.8.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.8.0.tgz#22d4ed96fe2451135299239feedb9fe1dcec780c"
|
||||
integrity sha512-+HDIGOEMnqbxdAHegxvnOqESUH6RWFRR2b8qxP1W9CZnnYh4Usz6MBL+2KMAgPk/P0o9c1HqnYtwzVH6GTIqug==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "5.8.0"
|
||||
eslint-visitor-keys "^3.0.0"
|
||||
|
||||
"@ungap/promise-all-settled@1.1.2":
|
||||
version "1.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44"
|
||||
|
@ -7382,6 +7428,13 @@ debug@^4.3.1:
|
|||
dependencies:
|
||||
ms "2.1.2"
|
||||
|
||||
debug@^4.3.2:
|
||||
version "4.3.3"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
|
||||
integrity sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==
|
||||
dependencies:
|
||||
ms "2.1.2"
|
||||
|
||||
decamelize@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290"
|
||||
|
@ -8145,6 +8198,13 @@ eslint-plugin-import@^2.17.2:
|
|||
resolve "^1.20.0"
|
||||
tsconfig-paths "^3.11.0"
|
||||
|
||||
eslint-plugin-jest@^25.3.0:
|
||||
version "25.3.0"
|
||||
resolved "https://registry.yarnpkg.com/eslint-plugin-jest/-/eslint-plugin-jest-25.3.0.tgz#6c04bbf13624a75684a05391a825b58e2e291950"
|
||||
integrity sha512-79WQtuBsTN1S8Y9+7euBYwxIOia/k7ykkl9OCBHL3xuww5ecursHy/D8GCIlvzHVWv85gOkS5Kv6Sh7RxOgK1Q==
|
||||
dependencies:
|
||||
"@typescript-eslint/experimental-utils" "^5.0.0"
|
||||
|
||||
eslint-plugin-jsx-a11y@6.3.1:
|
||||
version "6.3.1"
|
||||
resolved "https://registry.yarnpkg.com/eslint-plugin-jsx-a11y/-/eslint-plugin-jsx-a11y-6.3.1.tgz#99ef7e97f567cc6a5b8dd5ab95a94a67058a2660"
|
||||
|
@ -8241,6 +8301,11 @@ eslint-visitor-keys@^2.0.0, eslint-visitor-keys@^2.1.0:
|
|||
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz#f65328259305927392c938ed44eb0a5c9b2bd303"
|
||||
integrity sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==
|
||||
|
||||
eslint-visitor-keys@^3.0.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/eslint-visitor-keys/-/eslint-visitor-keys-3.1.0.tgz#eee4acea891814cda67a7d8812d9647dd0179af2"
|
||||
integrity sha512-yWJFpu4DtjsWKkt5GeNBBuZMlNcYVs6vRCLoCVEJrTjaSB6LC98gFipNK/erM2Heg/E8mIK+hXG/pJMLK+eRZA==
|
||||
|
||||
eslint@^7.31.0:
|
||||
version "7.32.0"
|
||||
resolved "https://registry.yarnpkg.com/eslint/-/eslint-7.32.0.tgz#c6d328a14be3fb08c8d1d21e12c02fdb7a2a812d"
|
||||
|
@ -9443,7 +9508,7 @@ globby@8.0.2:
|
|||
pify "^3.0.0"
|
||||
slash "^1.0.0"
|
||||
|
||||
globby@^11.0.3:
|
||||
globby@^11.0.3, globby@^11.0.4:
|
||||
version "11.0.4"
|
||||
resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5"
|
||||
integrity sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg==
|
||||
|
@ -10264,6 +10329,13 @@ is-glob@^4.0.0, is-glob@^4.0.1, is-glob@~4.0.1:
|
|||
dependencies:
|
||||
is-extglob "^2.1.1"
|
||||
|
||||
is-glob@^4.0.3:
|
||||
version "4.0.3"
|
||||
resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-4.0.3.tgz#64f61e42cbbb2eec2071a9dac0b28ba1e65d5084"
|
||||
integrity sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==
|
||||
dependencies:
|
||||
is-extglob "^2.1.1"
|
||||
|
||||
is-hexadecimal@^1.0.0:
|
||||
version "1.0.4"
|
||||
resolved "https://registry.yarnpkg.com/is-hexadecimal/-/is-hexadecimal-1.0.4.tgz#cc35c97588da4bd49a8eedd6bc4082d44dcb23a7"
|
||||
|
|
Loading…
Reference in New Issue