I am trying to test my react app using karma(on PhantomJS2), jasmine, and enzyme. I have noticed that some of my tests are failing. It seems to be because each it block is being called twice(I have confirmed this by putting prints in all my it blocks and they all print twice). I have looked up solutions, but none seem to work. I will include as much details as possible.
Here is my karma.config file:
files: [
{ pattern: 'test/**/*.tsx' }
],
I have also tried these but this had the same result as above:
files: [
{ pattern: 'test/**/*.tsx', watched: false, served: true, included: true }
],
I also tried this, but this caused karma to break:
files: [
{ pattern: 'test/**/*.tsx', included: false }
],
Here an example of one of my it blocks that runs twice(Although this passes if ran, the length being off is causing other tests to fail which I commented out):
it('renders the items', () => {
const wrapper = mount(<PortfolioList />);
const length = 5;
const items = fillArray(length);
// tslint:disable-next-line:no-console
console.log('LENGTH: ' + items.length); //OUTPUTS(twice): LENGTH: 10
wrapper.setState({results: items});
expect(wrapper.find('tbody').children().length).toBe(length);
});
Here is fillArray, even thought it is being called twice. Shouldn't it return an array of size 5 twice in my example? Why is it 10?:
function fillArray(length: number) {
const ary = new Array(length);
for (let i = 0; i < length; i++) {
ary.push(item);
}
return ary;
}
Here is a pic of what I feel is relevant(This is pasted together):