Closed Ahershel closed 6 years ago
$.extend is a jQuery function. toastr depends on jQuery. Are you loading it before toastr?
yes, i import the jquery in my test helper:
import { JSDOM } from 'jsdom';
import jQuery from 'jquery';
import chai, { expect } from 'chai';
import chaiJquery from 'chai-jquery';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
import { createStore, applyMiddleware } from 'redux';
import reducers from '../js/reducers/index.js';
import { MemoryRouter } from 'react-router-dom';
import { createMockStore } from 'redux-test-utils';
// Emulate browser in the terminal
const dom = new JSDOM('<!doctype html><html><body></body></html>');
global.document = dom.window.document;
global.window = global.document.defaultView;
global.navigator = {
userAgent: 'node.js'
};
var React = require('react');
var ReactDOM = require('react-dom');
var ReactTestUtils = require('react-dom/test-utils');
const $ = jQuery(window);
// Setup chaiJquery
chaiJquery(chai, chai.util, $);
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
// Helper function to render React Component/Container to return jQuery wrapped
// object.
function renderComponent(ComponentClass, props = {}, state = {}) {
const componentInstance = ReactTestUtils.renderIntoDocument(
<Provider store={createStoreWithMiddleware(reducers, state)}>
<MemoryRouter>
<ComponentClass {...props} />
</MemoryRouter>
</Provider>
);
return $(ReactDOM.findDOMNode(componentInstance));
}
// Helper function to simulate event on the renderComponent
$.fn.simulate = function (eventName, value) {
if (value) {
this.val(value);
}
ReactTestUtils.Simulate[eventName](this[0]);
};
export { renderComponent, expect };
the toastr is imported in my action:
import toastr from '../components/my_toastr.js';
my_toastr.js:
import toastr from 'toastr';
toastr.options = {
'closeButton': true,
'debug': false,
'newestOnTop': true,
'progressBar': false,
'positionClass': 'toast-top-right',
'preventDuplicates': true,
'onclick': null,
'showDuration': '300',
'hideDuration': '1000',
'timeOut': '0',
'extendedTimeOut': '1000',
'showEasing': 'swing',
'hideEasing': 'linear',
'showMethod': 'fadeIn',
'hideMethod': 'fadeOut'
};
export default toastr;
This doesn't sound like a toastr problem to me. Have you tried a simple script that imports jQuery and toastr then creates a toast?
I found the solution by doing this: in toastr.js (node_modules/toastr) I change the extend to Object.assign :
function getOptions() {
return Object.assign({}, getDefaults(), toastr.options);
}
Did you find a way to make it work in repeatable manner such that anyy other team member, who does npm install won't have this change manually? I am facing the same issue and your solution is the only one that's relevant to my scenario.
Is there a way to do this correctly? I am also getting an error for this!
I am also experiencing this with fullcalendar. just changing the $.extend to Object.assing doesn't seem like the best solution
Hi, i just use toastr for a few days. I have problem when testing my action (react). Here's the error:
I'm using mocha, chai and nock Here's my test code:
beside this error, it also give a warning on my console (testing result ):
my action code:
Pardon my English, it's not my native language.
Please help me, wether i made some mistakes or did i miss something. Thank you