Permalink
Browse files

Fixes UT

  • Loading branch information...
JbIPS committed Nov 23, 2017
1 parent 3dd6be2 commit d8eb9d3ec67544fb9bd9639b50560d9da2dcb66b
Showing with 92 additions and 57 deletions.
  1. +1 −1 .travis.yml
  2. +16 −0 __tests__/.eslintrc.json
  3. +0 −51 __tests__/TestUnifileService.js
  4. +64 −0 __tests__/UnifileService.test.js
  5. +10 −4 package.json
  6. +1 −1 src/js/.eslintrc.json
View
@@ -12,5 +12,5 @@ addons:
install:
- npm install
script:
# - npm test
- npm test
- npm run lint
View
@@ -0,0 +1,16 @@
{
"env": {
"browser": true,
"jest": true
},
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 8
},
"globals": {
"fail": true
},
"rules": {
"no-invalid-this": ["off"]
}
}

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,64 @@
jest.dontMock('react');
jest.dontMock('react-dom');
jest.dontMock('react-addons-test-utils');
jest.unmock('../src/js/UnifileService');
const UnifileService = require('../src/js/UnifileService').default;
const OK_STATUS = 200;
describe('UnifileService', () => {
it('ls success', async () => {
const jsonObject = [
{
bytes: 1234,
isDir: false,
modified: '2016-05-07T22:10:31',
name: 'README.md'
},
{
isDir: true,
modified: '2016-05-07T22:10:31',
name: 'test'
}
];
Object.defineProperty(XMLHttpRequest.prototype, 'responseText', {
get () {
return JSON.stringify(jsonObject);
}
});
Object.defineProperty(XMLHttpRequest.prototype, 'status', {
get () {
return OK_STATUS;
}
});
XMLHttpRequest.prototype.open = jest.fn(function open () {
this.onload();
});
XMLHttpRequest.prototype.getResponseHeader = jest.fn((header) => {
if (header.toLowerCase() === 'content-type') return 'application/json';
return '';
});
const srv = new UnifileService('http://localhost:8080/dist/');
await srv.ls(['ftp'])
.catch((e) => {
fail(`There has been an error: ${e.message}`);
})
.then((data) => {
expect(data).toEqual(jsonObject);
});
});
it('ls error', async () => {
XMLHttpRequest.prototype.open = jest.fn(function open () {
this.onerror({});
});
const srv = new UnifileService('http://localhost:8080/dist/');
await srv.ls('ftp')
.then(() => fail('There should have been an error'))
.catch((e) => expect(e).not.toBe(null));
});
afterEach(() => {
XMLHttpRequest.prototype.open.mockClear();
});
});
View
@@ -11,13 +11,13 @@
"postinstall": "npm run build:fonts && npm run build",
"start": "node lib/index.js",
"test": "jest",
"test:watch": "watch 'npm test' src/ __tests__/",
"test:watch": "npm test -- --watch",
"build": "npm run build:js && npm run build:sass",
"build:fonts": "mkdir -p dist/fonts && cp -R `node_modules`/font-awesome/fonts/* `node_modules`/npm-font-open-sans/fonts/* dist/fonts/",
"build:js": "browserify --extension=jsx src/js/App.jsx -d -o dist/cloud-explorer.js -t [ babelify ]",
"build:sass": "node-sass --include-path src/sass --include-path node_modules/font-awesome/scss src/sass/style.scss dist/style.css",
"lint": "npm run lint:client && npm run lint:server",
"lint:client": "eslint --ext .jsx,.js src/js",
"lint:client": "eslint --ext .jsx,.js src/js __tests__",
"lint:server": "eslint lib/",
"watch": "live-reload dist/ --port 35729 & watch 'npm run build:js' src/js & watch 'npm run build:sass' src/sass"
},
@@ -56,13 +56,19 @@
"eslint": "^4.11.0",
"eslint-plugin-node": "^5.2.1",
"eslint-plugin-react": "^7.4.0",
"jest-cli": "^13.2.3",
"jest": "^21.2.1",
"jest-localstorage-mock": "^2.1.0",
"live-reload": "^1.1.0",
"pre-commit": "^1.2.2",
"react-addons-test-utils": "^15.2.0",
"watch": "^0.19.1"
},
"precommit": [
"lint"
]
],
"jest": {
"setupFiles": [
"jest-localstorage-mock"
]
}
}
View
@@ -22,7 +22,7 @@
"jsx": true
}
},
"extends": ["plugin:react/all"],
"extends": ["plugin:react/recommended"],
"rules": {
"react/jsx-indent": ["error", 2],
"react/jsx-indent-props": ["error", 2],

0 comments on commit d8eb9d3

Please sign in to comment.