Skip to content

Commit

Permalink
Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed May 9, 2017
1 parent 80eae70 commit b9f0347
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
20 changes: 17 additions & 3 deletions superset/assets/spec/helpers/browser.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/* eslint no-undef: 0, no-native-reassign: 0 */
import 'babel-polyfill';
import chai from 'chai';
import jsdom from 'jsdom';

require('babel-register')();

const jsdom = require('jsdom').jsdom;
global.sinon = require('sinon');

const exposedProperties = ['window', 'navigator', 'document'];

global.document = jsdom('');
global.document = jsdom.jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
Expand All @@ -20,3 +22,15 @@ global.navigator = {
platform: 'linux',
appName: 'Netscape',
};

// Configuration copied from https://github.com/sinonjs/sinon/issues/657
// allowing for sinon.fakeServer to work
global.jsdom = jsdom.jsdom;
global.document = global.jsdom('<!doctype html><html><body></body></html>');
global.window = global.document.defaultView;
global.XMLHttpRequest = global.window.XMLHttpRequest;
global.expect = chai.expect;
global.assert = chai.assert;
global.sinon.useFakeXMLHttpRequest();
global.window.XMLHttpRequest = global.XMLHttpRequest;
global.$ = require('jquery')(global.window);
22 changes: 11 additions & 11 deletions superset/assets/spec/javascripts/components/AsyncSelect_spec.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';
import Select from 'react-select';
import { shallow } from 'enzyme';
import { mount, shallow } from 'enzyme';
import { describe, it } from 'mocha';
import { expect } from 'chai';
import sinon from 'sinon';
import $ from 'jquery';

import AsyncSelect from '../../../javascripts/components/AsyncSelect';

Expand Down Expand Up @@ -39,30 +38,31 @@ describe('AsyncSelect', () => {
});

describe('auto select', () => {
let stub;
let server;
beforeEach(() => {
stub = sinon.stub($, 'get');
stub.yields();
server = sinon.fakeServer.create();
server.respondWith([
200, { 'Content-Type': 'application/json' }, JSON.stringify({}),
]);
});
afterEach(() => {
stub.restore();
server.restore();
});
it('should be off by default', () => {
const wrapper = shallow(
const wrapper = mount(
<AsyncSelect {...mockedProps} />,
);
const spy = sinon.spy(wrapper.instance(), 'onChange');

wrapper.instance().fetchOptions();
expect(spy.callCount).to.equal(0);
});
it('should auto select first option', () => {
const wrapper = shallow(
const wrapper = mount(
<AsyncSelect {...mockedProps} autoSelect />,
);
const spy = sinon.spy(wrapper.instance(), 'onChange');
server.respond();

wrapper.instance().fetchOptions();
expect(spy.callCount).to.equal(1);
expect(spy.calledWith(wrapper.instance().state.options[0])).to.equal(true);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { table, defaultQueryEditor } from './fixtures';
import SqlEditorLeftBar from '../../../javascripts/SqlLab/components/SqlEditorLeftBar';
import TableElement from '../../../javascripts/SqlLab/components/TableElement';

global.notify = {
error: () => {},
};

describe('SqlEditorLeftBar', () => {
const mockedProps = {
Expand Down

0 comments on commit b9f0347

Please sign in to comment.