Add jest/enzyme and a simple unit test
This commit is contained in:
parent
772a7c9370
commit
e1ef323e9b
7 changed files with 16702 additions and 4265 deletions
|
@ -4,7 +4,7 @@
|
|||
"env": {
|
||||
"browser": true,
|
||||
"node": true,
|
||||
"mocha": true
|
||||
"jest": true
|
||||
},
|
||||
"rules": {
|
||||
"linebreak-style": 0,
|
||||
|
|
1
client/__test__/mocks/fileMock.js
Normal file
1
client/__test__/mocks/fileMock.js
Normal file
|
@ -0,0 +1 @@
|
|||
module.exports = 'test-file-stub';
|
47
client/components/__test__/Nav.test.jsx
Normal file
47
client/components/__test__/Nav.test.jsx
Normal file
|
@ -0,0 +1,47 @@
|
|||
|
||||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
|
||||
import Nav from './../Nav';
|
||||
|
||||
describe('Nav', () => {
|
||||
const props = {
|
||||
newProject: jest.fn(),
|
||||
saveProject: jest.fn(),
|
||||
autosaveProject: jest.fn(),
|
||||
exportProjectAsZip: jest.fn(),
|
||||
cloneProject: jest.fn(),
|
||||
user: {
|
||||
authenticated: true,
|
||||
username: 'new-user',
|
||||
id: 'new-user'
|
||||
},
|
||||
project: {
|
||||
id: 'new-project',
|
||||
owner: {
|
||||
id: 'new-user'
|
||||
}
|
||||
},
|
||||
logoutUser: jest.fn(),
|
||||
showShareModal: jest.fn(),
|
||||
showErrorModal: jest.fn(),
|
||||
unsavedChanges: false,
|
||||
warnIfUnsavedChanges: jest.fn(),
|
||||
showKeyboardShortcutModal: jest.fn(),
|
||||
cmController: {
|
||||
tidyCode: jest.fn(),
|
||||
showFind: jest.fn(),
|
||||
findNext: jest.fn(),
|
||||
findPrev: jest.fn()
|
||||
},
|
||||
startSketch: jest.fn(),
|
||||
stopSketch: jest.fn(),
|
||||
setAllAccessibleOutput: jest.fn()
|
||||
};
|
||||
const getWrapper = () => shallow(<Nav {...props} />);
|
||||
|
||||
test('it renders main navigation', () => {
|
||||
const nav = getWrapper();
|
||||
expect(nav.exists('.nav')).toEqual(true);
|
||||
});
|
||||
});
|
|
@ -29,6 +29,9 @@ Follow these instructions to set up your development environment, which you need
|
|||
11. Install the [React Developer Tools](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en)
|
||||
12. Open and close the Redux DevTools using `ctrl+h`, and move them with `ctrl+w`
|
||||
|
||||
## Tests (in progress)
|
||||
Run `npm test`
|
||||
|
||||
## Docker Installation
|
||||
|
||||
Using Docker, you can have a complete, consistent development environment without having to manually install dependencies such as Node, Mongo, etc. It also helps isolate these dependencies and their data from other projects that you may have on the same computer that use different/conflicting versions, etc.
|
||||
|
|
4
jest.setup.js
Normal file
4
jest.setup.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
import { configure } from 'enzyme'
|
||||
import Adapter from 'enzyme-adapter-react-16'
|
||||
|
||||
configure({ adapter: new Adapter() })
|
20897
package-lock.json
generated
20897
package-lock.json
generated
File diff suppressed because it is too large
Load diff
13
package.json
13
package.json
|
@ -12,13 +12,21 @@
|
|||
"build:client": "cross-env NODE_ENV=production webpack --config webpack/config.prod.js",
|
||||
"build:server": "cross-env NODE_ENV=production webpack --config webpack/config.server.js",
|
||||
"build:examples": "cross-env NODE_ENV=production webpack --config webpack/config.examples.js",
|
||||
"test": "npm run lint",
|
||||
"test": "jest",
|
||||
"fetch-examples": "cross-env NODE_ENV=development node ./server/scripts/fetch-examples.js",
|
||||
"fetch-examples-gg": "cross-env NODE_ENV=development node ./server/scripts/fetch-examples-gg.js",
|
||||
"fetch-examples:prod": "cross-env NODE_ENV=production node ./dist/fetch-examples.bundle.js",
|
||||
"fetch-examples-gg:prod": "cross-env NODE_ENV=production node ./dist/fetch-examples-gg.bundle.js",
|
||||
"heroku-postbuild": "touch .env; npm run build"
|
||||
},
|
||||
"jest": {
|
||||
"setupFiles": [
|
||||
"<rootDir>/jest.setup.js"
|
||||
],
|
||||
"moduleNameMapper": {
|
||||
"^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/client/__test__/mocks/fileMock.js"
|
||||
}
|
||||
},
|
||||
"main": "index.js",
|
||||
"author": "Cassie Tarakajian",
|
||||
"license": "LGPL-2.1",
|
||||
|
@ -41,6 +49,8 @@
|
|||
"css-loader": "^0.23.1",
|
||||
"cssnano": "^3.10.0",
|
||||
"eslint": "^4.19.1",
|
||||
"enzyme": "^3.7.0",
|
||||
"enzyme-adapter-react-16": "^1.6.0",
|
||||
"eslint-config-airbnb": "^16.1.0",
|
||||
"eslint-plugin-import": "^2.14.0",
|
||||
"eslint-plugin-jsx-a11y": "^6.1.2",
|
||||
|
@ -50,6 +60,7 @@
|
|||
"node-sass": "^4.11.0",
|
||||
"nodemon": "^1.18.9",
|
||||
"postcss-cssnext": "^2.11.0",
|
||||
"jest": "^23.6.0",
|
||||
"postcss-focus": "^1.0.0",
|
||||
"postcss-loader": "^0.9.1",
|
||||
"postcss-reporter": "^1.4.1",
|
||||
|
|
Loading…
Reference in a new issue