Skip to content

Commit

Permalink
fix: fix test warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lightbringer1991 committed May 7, 2019
1 parent d2b1cbb commit 319daee
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
39 changes: 37 additions & 2 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const webpackConfig = require('./webpack.config');
const webpack = require('webpack');
const _ = require('lodash');
const webpack = require('webpack');
const webpackConfig = require('./webpack.config');

const env = { ADSLOT_TEST_FILE: '' };
process.env.CHROME_BIN = require('puppeteer').executablePath();
Expand All @@ -14,6 +14,29 @@ webpackConfig.plugins.push(
)
);

/**
* middleware to reply to all image requests with a fake image
*/
exports.ignoreImagesMw = (req, res, next) => {
const imageExt = req.url.split('.').pop();

if (!_.includes(['png', 'jpg', 'jpeg', 'svg'], imageExt)) {
return next();
}

const fakeImageResponse = {
data: Buffer.from('data:image/gif;base64,R0lGODlhAQABAAAAACwAAAAAAQABAAA=', 'base64'),
type: 'image/gif',
};

res.writeHead(200, {
'Content-Type': fakeImageResponse.type,
'Content-Length': fakeImageResponse.data.length,
});

return res.end(fakeImageResponse.data);
};

module.exports = function configureKarma(config) {
config.set({
basePath: '',
Expand All @@ -25,6 +48,7 @@ module.exports = function configureKarma(config) {
port: 8080,
captureTimeout: 60000,
frameworks: ['mocha', 'chai'],
middleware: ['ignoreImagesMw'],
browserConsoleLogOptions: {
level: 'log',
format: '%b %T: %m',
Expand Down Expand Up @@ -56,6 +80,17 @@ module.exports = function configureKarma(config) {
},
},
},
plugins: [
'karma-webpack',
'karma-chrome-launcher',
'karma-mocha',
'karma-mocha-reporter',
'karma-coverage',
'karma-chai',
{
'middleware:ignoreImagesMw': ['value', exports.ignoreImagesMw],
},
],
webpack: webpackConfig,
webpackMiddleware: {
noInfo: true,
Expand Down
3 changes: 1 addition & 2 deletions src/components/adslot-ui/Checkbox/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash';
import React from 'react';
import classnames from 'classnames';
import { expandDts } from '../../../lib/utils';
import { checkboxPropTypes, checkboxCheckStates } from '../../prop-types/inputPropTypes';
import { checkboxPropTypes } from '../../prop-types/inputPropTypes';
import './styles.scss';

const getNextState = checked => {
Expand All @@ -11,7 +11,6 @@ const getNextState = checked => {
};

const Checkbox = ({ name, value, label, dts, disabled, checked, id, className, inline, onChange, size }) => {
if (!_.includes(checkboxCheckStates, checked)) throw new Error("The 'checked' prop should be boolean or 'partial'");
const componentClassName = classnames([
'checkbox-component',
{
Expand Down
8 changes: 0 additions & 8 deletions src/components/adslot-ui/Checkbox/index.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ describe('Checkbox', () => {
expect(component.hasClass('disabled')).to.equal(true);
});

it('should throw error if checked value is not accepted', () => {
try {
shallow(<Checkbox name="test" checked="test" />);
} catch (err) {
expect(err.message).to.equal("The 'checked' prop should be boolean or 'partial'");
}
});

it('should pass next state valut to the onChange function', () => {
const handleChange = sinon.spy();
const component = shallow(<Checkbox name="name" value="value" onChange={handleChange} />);
Expand Down

0 comments on commit 319daee

Please sign in to comment.